Write a 'c' program to calculate the frequencies of different alphabets present in a given string the string of alphabets is to be taken as input from the keyboard?

1 answer

Answer

1228977

2026-07-13 22:40

+ Follow

/* For a short string, like "abaz" a Hashmap like (a:2, b:1, z:1) will be shorter, than a whole alphabet*/

#include<stdio.h>

#include<conio.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();

}

/*Answered by Ankush Monga

Doing DOEACC B level*/

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.