AD1

Tuesday, 28 February 2017

compute occurrence of character in a string

write C Program print the frequency of a certain character in a string 

#include <stdio.h>
#include <string.h>
int main(void) {
printf("enter the string\n");
char string[50];char c;int i=0;int counter=0;
gets(string);
printf("enter the character you want to compute its occurrence\n");
scanf("%c",&c);
while(string[i]!='\0')
{
if(string[i]==c){counter++;i++;}
else {i++;continue;}
}
printf("%c occured %d times with frequency %f %c\n",c,counter,100*(float)counter/i,'%');
return 0;
}
view raw freq.c hosted with ❤ by GitHub

No comments:

Post a Comment