Character Frequency
Write a program to compute the frequency of characters other than space.
Sample Input 1
Pop up
Sample Output 1
o: 1
p: 3
u: 1
#include <stdio.h>
int main() {
char *s;
int count['z'+1];
scanf("%s", &s);
for (int i = 0; i < sizeof(s) / sizeof(char); i++) {
count[s[i]]++;
}
for (int i = 'a'; i <= 'z'; i++) {
if (count[i]) {
printf("%c: %d\n", i, count[i]);
}
}
return 0;
}
Comments
Leave a comment