write C Program print the frequency of a certain character in a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |