#include<stdio.h>
int main (void)
{
int a; int arr[27]; int total =0; char letter; float freq;
// assigns the value of zero to the whole array
for(int k =1; k<27; k++){
arr[k] = 0;
}
while( a != EOF){
a = getchar();
if (a == EOF){
break;
}
// converts letters to lower case
if( (a >= 'A') && (a <= 'Z') ){
a = a + 32;
}
if ((a>= 'a') && (a<= 'z')){
total++;
int index = a-96;
arr[index]= arr[index]+1;
}
}
for (int x = 1;x<27; x++){
if (arr[x] != 0){
letter = (char)(x+96);
freq = (float)arr[x]/total;
printf( "%c %.4f\n", letter, freq);
}
}
return 0;
}
No comments:
Post a Comment