Count uppercase and lowercase characters in a string
C program to count uppercase and lowercase characters in a string.
Program
#include<stdio.h>
#include<conio.h>
#define MAX 50
void main()
{
char str[MAX];
int i, upper, lower;
printf("Enter the string\t:");
gets(str);
upper = 0;
lower = 0;
i = 0;
while(str[i] != '\0')
{
if(str[i]>='A' && str[i]<='Z')
upper++;
else if(str[i]>='a' && str[i]<='z')
lower++;
i++;
}
printf("\nNumber of Uppercase letters\t:%d",upper);
printf("\nNumber of Lowercase letters\t:%d",lower);
getch();
}
Output
Enter the string :Welcome to CourseCrux.com
Number of Uppercase letters :3
Number of Lowercase letters :19