Tuesday 30 January 2018

Count frequency of each character

Q : Write a program to count frequency of each character individually.

Solution : 

/*==============================
     Girfa Student Help
     Program : Count frequency of each character
     More Program :http://girfahelp.blogspot.in/p/1.html
================================*/
#include<stdio.h>
#include<conio.h>
#define MAX 50
void main()
{
     char ar[MAX],temp[26];
     int i,j,k,s;
     clrscr();
     printf("Enter String>> ");
     gets(ar);
     temp[0]=ar[0];
     for(i=0,j=1;ar[i]!='\0';i++)
     {
          for(k=0;k<j;k++)
          {

              if(ar[i]==temp[k])
                   break;
          }
          if(k==j)
              temp[j++]=ar[i];
     }
     printf("\nFrequency of character is follows\n");
     for(i=0;i<j;i++)
     {
          for(k=0,s=0;ar[k]!='\0';k++)
          {
              if(temp[i]==ar[k])
                   s++;
          }
          printf("\n%c = %d",temp[i],s);
     }
     getch();
}

No comments:

Post a Comment