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



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

Answer / 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

More C Interview Questions

write a string copy function routine?

2 Answers  


difference between c and c++?

2 Answers  


Why array is used in c?

0 Answers  


what are # pragma staments?

0 Answers  


simple program for virtual function?

1 Answers  


How can a program be made to print the name of a source file where an error occurs?

0 Answers  


What is 2 d array in c?

0 Answers  


what defference between c and c++ ?

6 Answers  


Write a program to swap two numbers without using third variable in c?

0 Answers  


What is your stream meaning?

0 Answers  


Explain main function in c?

0 Answers  


any "C" function by default returns an a) int value b) float value c) char value d) a & b

0 Answers  


Categories