void main()
{
char s[100];
int f[26]={0},i,j;
clrscr();
scanf("%s",s);
for(i=0;s[i]!='\0';i++)
{
f[s[i]-'a']++;
}
for(i=0;i<26;i++)
{
if(f[i]>0)
printf("%c occurs %d times\n",i+'a',f[i]);
}
}
input:
hello
output:
e occurs 1 times
h occurs 1 times
l occurs 2 times
o occurs 1 times
{
char s[100];
int f[26]={0},i,j;
clrscr();
scanf("%s",s);
for(i=0;s[i]!='\0';i++)
{
f[s[i]-'a']++;
}
for(i=0;i<26;i++)
{
if(f[i]>0)
printf("%c occurs %d times\n",i+'a',f[i]);
}
}
input:
hello
output:
e occurs 1 times
h occurs 1 times
l occurs 2 times
o occurs 1 times
No comments:
Post a Comment