C program to count number of letters(Total and individually) in the given string:
#include <stdio.h>
int main()
{
char str[100];
int i,j,cnt,t=0;
printf("enter string:");
gets(str);
printf("\nentered string is:");
puts(str);
printf("the number of letters individually in the given string:\n");
for(i=0;str[i];i++)
{
cnt=1;
for(j=i+1;str[j];j++)
{
if(str[i]==str[j] && str[i]!=' ')
{
cnt++;
str[j]='0';
}
}
if(cnt >=1 && str[i] != '0' && str[i]!=' ')
{
printf("%c=%d\n", str[i],cnt);
t=t+cnt;
}
}
printf("total number of letters in the given string is %d",t);
return 0;
}
Comments
Post a Comment