belongs to collection: C language string programs
C Program to Count number of Lowercase and Uppercase Letters.
Solution:
I have used Code:: Blocks compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
#include <stdio.h> #include <string.h> int main() { char string[100]; int c = 0, count[26] = {0}; printf("Enter a string:\t"); gets(string); while ( string[c] != '\0' ) { if ( string[c] >= 'a' && string[c] <= 'z' ) count[string[c]-'a']++; else if(string[c] >= 'A' && string[c] <= 'Z' ) count[string[c]-'A']++; else printf("ERROR!!\n"); c++; } for ( c = 0 ; c < 26 ; c++ ) { if( count[c] != 0 ) printf("%c : %d\n",c+'a',count[c]); } return 0; }
Result:
Enter a string: helloworld
d : 1
e : 1
h : 1
l : 3
o : 2
r : 1
w : 1
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Solution:
I have used Code:: Blocks compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
Result:
Enter a string: helloworld
d : 1
e : 1
h : 1
l : 3
o : 2
r : 1
w : 1
need an explanation for this answer? contact us directly to get an explanation for this answer