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
Explain what are the __date__ and __time__ preprocessor commands?
What is volatile variable in c?
a value that does not change during program execution a) variabe b) argument c) parameter d) none
write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1
How variables are declared in c?
What is the use of bitwise operator?
Explain the use of 'auto' keyword in c programming?
Who developed c language and when?
What is the difference between functions getch() and getche()?
How can this be legal c?
What is the purpose of 'register' keyword in c language?
List the variables are used for writing doubly linked list program.
What is meant by initialization and how we initialize a variable?
Explain what is the benefit of using const for declaring constants?
What are 'near' and 'far' pointers?