New Android apps UniqueKey

Sunday 22 February 2015

No. of particular character in a string.


#include <stdio.h>

main()
{
   char c[100],ch;
   int i,count=0;
   
   printf("Enter a string: ");
   gets(c);
   printf("Enter a character to find frequency: ");
   scanf("%c",&ch);
   
   for(i=0;c[i]!='\0';i++)
   {
       if(ch==c[i])
           count++;
   }
   printf("Frequency of %c = %d", ch, count);
}

No comments:

Post a Comment