Question : c program to find the frequency of all characters in a string
Answered by : healthy-hare-aoylwn8hvx1u
#include <stdio.h>
#include <string.h>
int main()
{
char s[1000];
int i,j,k,count=0,n;
printf("Enter the string : ");
gets(s);
for(j=0;s[j];j++); n=j;
printf(" frequency count character in string:\n");
for(i=0;i<n;i++)
{
count=1;
if(s[i])
{ for(j=i+1;j<n;j++) { if(s[i]==s[j])
{
count++;
s[j]='\0'; } } printf(" '%c' = %d \n",s[i],count);
} }
return 0;
}
Source : https://javatutoring.com/c-program-count-frequency-of-each-character-in-string/ | Last Update : Thu, 26 May 22
Question : c program to find the frequency of characters in a string
Answered by : healthy-hare-aoylwn8hvx1u
#include <stdio.h>
int main() { char str[1000], ch; int count = 0; printf("Enter a string: "); fgets(str, sizeof(str), stdin); printf("Enter a character to find its frequency: "); scanf("%c", &ch); for (int i = 0; str[i] != '\0'; ++i) { if (ch == str[i]) ++count; } printf("Frequency of %c = %d", ch, count); return 0;
}
Source : https://www.programiz.com/c-programming/examples/frequency-character | Last Update : Thu, 26 May 22