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

#ifdef TRUE int I=0; #endif main() { int j=0; printf("%d %d\n",i,j); }

3 Answers   ADITI,


Write a code on reverse string and its complexity.

0 Answers   Expedia,


Write code for finding depth of tree

2 Answers   Adobe,


Find the largest number from the given 2 numbers without using any loops and the conditional operator.

2 Answers  


write a program to find the number of even integers and odd integers in a given array in c language

13 Answers   IAI Cameroun, NIIT, Olive Tech, QIS,






a=(1,2,3); b=1,2,3; c=1,(2,3); d=(1,2),3; what's the value of 'a','b','c','d'

2 Answers  


main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); }

3 Answers   ME,


define function

4 Answers   Assurgent, Sonata,


What is floating point exception error? And what are different types of errors occur during compile time and run time? why they occur?

1 Answers  


Is that possible to store 32768 in an int data type variable?

0 Answers  


What are the usage of pointer in c?

0 Answers  


Difference between MAC vs. IP Addressing

0 Answers  


Categories