Tuesday 23 April 2013

C Program to count frequency of characters in the given string

#include<stdio.h>
#include<conio.h>

#include<string.h>
main()
{
int count,i,j;
char str[50];
printf("Enter string : ");
gets(str);
for(i=0;i<=strlen(str)-1;i++)
{
count=1;
if(str[i]==' ')
continue;
for(j=i+1;j<=strlen(str)-1;j++)
{
if(str[i]==str[j])
{
str[j]=' ';
count++;
}
}
printf("%c : %d \n",str[i],count);
}
getch();
}

No comments:

Post a Comment