write a program to display the frequency of each element in
a given array in c language

Answer Posted / gaurav gangopadhyay

#include<stdio.h>
#include<conio.h>
void main()
{
char ch[10],stk[10];
int i=0;frq[10],b=-1,k,j;
printf("Enter string:");
gets(ch);
while(ch[i]!='\0')
{
if(b==-1)
{
b++;
stk[b]=ch[i];
frq[b]=frq[b]+1;
}
else
{
k=0;
for(j=0;j<=b;j++)
{
if(stk[j]==ch[i])
{
frq[j]=frq[j]+1;
k=1;
break;
}
}
if(k==0)
{
b++;
stk[b]=ch[i];
frq[b]=frq[b]+1;
}
}
i++;
}
for(i=0;i<=b;i++)
printf("\nNo of %c=%d",stk[i],frq[i]);
getch();
}

Is This Answer Correct ?    4 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what are the __date__ and __time__ preprocessor commands?

596


What is volatile variable in c?

660


a value that does not change during program execution a) variabe b) argument c) parameter d) none

699


write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1

3299


How variables are declared in c?

576






What is the use of bitwise operator?

694


Explain the use of 'auto' keyword in c programming?

685


Who developed c language and when?

589


What is the difference between functions getch() and getche()?

625


How can this be legal c?

656


What is the purpose of 'register' keyword in c language?

631


List the variables are used for writing doubly linked list program.

1626


What is meant by initialization and how we initialize a variable?

590


Explain what is the benefit of using const for declaring constants?

618


What are 'near' and 'far' pointers?

624