C Program to Count number of Uppercase and Lowercase Letters
Count Total number of Capital and Small Letters from Accepted Line
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include<stdio.h> int main() { int upper = 0, lower = 0; char ch[80]; int i; printf("\nEnter The String : "); gets(ch); i = 0; while (ch[i] != '') { if (ch[i] >= 'A' && ch[i] <= 'Z') upper++; if (ch[i] >= 'a' && ch[i] <= 'z') lower++; i++; } printf("\nUppercase Letters : %d", upper); printf("\nLowercase Letters : %d", lower); return (0); } |
Output :
1 2 3 |
Enter The String : Pritesh A Taral Uppercase Letters : 3 Lowercase Letters : 10 |
Program Categorized Under : String Programs in C
Explanation :
1 |
if(ch[i]>='A' && ch[i]< ='Z') |
- We can compare two Characters.
- Generally Comparing Characters means Comparing Corresponding ASCII Values.
1 |
if('Z' > 'A') |
meanse
1 2 3 |
if('Z' > 'A') = if(ASCII Value 'Z' > ASCII Value 'A') = if(90 > 65) |