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 code to reverse string seperated by spaces i/p str=India is my country o/p str=aidnI si ym yrtnuoc After writing code, optimize the code

1 Answers  


how many errors in c explain deply

0 Answers  


why we are using semicolon at the end of printh statment

2 Answers   HCL,


number of times a digit is present in a number

0 Answers  


How to write a code for random pick from 1-1000 numbers? The output should contain the 10 numbers from the range 1-1000 which should pick randomly, ie ,for each time we run the code we should get different outputs.

12 Answers   NetApp,






How can I find leaf node with smallest level in a binary tree?

1 Answers  


What is the Purpose of 'extern' keyword in a function declaration?

0 Answers  


errors in computer programmes are called

1 Answers   NET,


how to find the binary of a number?

10 Answers   Infosys,


find the size of structure without using the size of function

1 Answers   Bosch,


main() { printf(5+"good morning"); printf("%c","abcdefgh"[4]); }the o/p is morning and e...how someone explain

1 Answers  


What is the heap?

0 Answers  


Categories