Frequency of character

Program:

#include <stdio.h>
int main()
{
   char str[300], ch;
   int i, frequency = 0;
   printf("Enter a string: ");
   gets(str);
   printf("Enter a character to find the frequency: ");
   scanf("%c",&ch);
   for(i=0;str[i]!='\0';i++)
   {
       if(ch==str[i])
        {
          frequency++;
}
   }
   printf("Frequency of %c = %d", ch, frequency);
   return 0;
}

Output:



No comments:

Post a Comment

x^y using recursion

Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...