Letter Counter of String in C#

/*
Summary: Counts frequency of letters in given string
*/

#include
#include

int main()
{
char string[100];
int c = 0, count[26] = {0};

printf("Enter a string\n");
gets(string);

while ( string[c] != '\0' )
{
/* Considering characters from 'a' to 'z' only */

if ( string[c] >= 'a' && string[c] <= 'z' )
count[string[c]-'a']++;

c++;
}




for ( c = 0 ; c < 26 ; c++ )
{
if( count[c] != 0 )
printf("%c occurs %d times in the entered string.\n",c+'a',count[c]);
}

return 0;
}

_______________________________OUPUT______________________________

Enter a string
universitymcqs
c occurs 1 times in the entered string.
e occurs 1 times in the entered string.
i occurs 2 times in the entered string.
m occurs 1 times in the entered string.
n occurs 1 times in the entered string.
q occurs 1 times in the entered string.
r occurs 1 times in the entered string.
s occurs 2 times in the entered string.
t occurs 1 times in the entered string.
u occurs 1 times in the entered string.
v occurs 1 times in the entered string.
y occurs 1 times in the entered string.


Alphabetical sort in C#




Share: