Sunday, July 12, 2009

C programming?

I am storing some text into a string and I need to find the frequency of each letter in the text in terms of percentages. Can anyone help me?

C programming?
have variables to count the string and have a if.. elseif structure to check for each character.. For example,


if(a[i]="a")


counter1++;;


else if(a[i]="b"


counter2++;


.


.


.





and so on.. finally, u can use the counters used to get the percentages...
Reply:I hope this will help -


let count be an array of 26 elements (0-25)


len to store length of string


str be the string





len=strlen(str);


for (i=0;i%26lt;len;i++)


for(j='a';j%26lt;='z';j++)


if(str[i]=strchr(j))


count[j-'a']++;





for(i=0;i%26lt;26;i++)


printf("\nfrequency of %c-%f",i+'a',count[i]/len*100);


No comments:

Post a Comment