1.
Write a program in C to count total number of
alphabets, digits and special characters in a string.
#include <stdio.h>
#include <ctype.h>
int main() {
char str[100];
int alphabets = 0, digits = 0, specialChars = 0;
printf("Enter a string : ");
fgets(str, sizeof(str), stdin);
for (int i = 0; str[i] != '\0'; i++) {
if (isalpha(str[i])) {
alphabets++;
else if (isdigit(str[i])) {
digits++;
else if (isspace(str[i])) {
specialChars++;
printf("No. Of Alphabets: %d\n", alphabets);
printf("No. Of Digits: %d\n", digits);
printf("No. Of Special characters: %d\n", specialChars);
return 0;
}
OUTPUT:-
2.Write a C program to sort a string array in ascending
order.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void sortString(char str[]) {
int n = strlen(str);
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (str[i] > str[j]) {
char temp = str[i];
str[i] = str[j];
str[j] = temp;
int main() {
char str[100];
printf("Input the string: ");
fgets(str, sizeof(str), stdin);
sortString(str);
printf("After sorting the string appears like: %s", str);
return 0;
OUTPUT:-
3.Write a program in C to read a sentence and replace
lowercase characters by uppercase and vice-versa.
#include <stdio.h>
#include <ctype.h>
int main() {
char str[100];
printf("Input the string: ");
fgets(str, sizeof(str), stdin);
for ( int i = 0; str[i] != '\0'; i++) {
if (islower(str[i])) {
str[i] = toupper(str[i]);
} else if (isupper(str[i])) {
str[i] = tolower(str[i]);
}
printf("After case conversion, the string is: %s", str);
return 0;
OUTPUT:-