Sunday, 23 February 2014

c program Frequency of Array Elements

 c program Frequency of Array Elements

in this c program we find the  Frequency of Array Elements this programm tell us  Frequency of Array Elements
connting the Frequencies  of  Element  of array
#include<stdio.h>
#define s 6
int main()
{
int a[s],freq[s];
int i,j,k,n=s;
for(i=0;i<s;i++)
{
printf("\n Enter a[%d] Element ",i);
scanf("%d",&a[i]);
freq[i]=1;


}
printf("Orignal array\n");
for(i=0;i<s;i++)
printf("%d",a[i]);
//main  logic stats here
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(a[i]==a[j])
{
for(k=j;k<n;k++)
a[k]=a[k+1];
freq[i]++;
n--;


}
}
printf("\n array with freq\n");
printf("\n Elemetnt freq");
for(i=0;i<n;i++)
printf("%d %d\n",a[i],freq[i]);
}

No comments:

Post a Comment