A Program to calculate the frequency of a number in an array


hi guys . a new program  is there for you now.this program justs calculate frequency of a number occurring in an array of 10 elements.


#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,j,flag,m[10];
clrscr();
printf("Enter 10 numbers\n");
for(i=0;i<10;i++)
{
  scanf("%d",&a[i]);
 }
 printf("\nno.     occurrence\n");
 for(i=0;i<10;i++)
 {
  flag=0;
  m[i]=a[i];
  if(i>0)
  {
    j=0;
    while(j<i)
    {
       if(m[j]==a[i])
       {
     j=i+1;
    }
       else j++;
     }
     if(j==i)
     {
       for(j=0;j<10;j++)
       {
     if(a[j]==m[i])
     {
       flag=flag++;
      }
     }
    printf("%d    %d\n",a[i],flag);
      }
   }
  else
  {
    for(j=0;j<10;j++)
    {
      if(a[j]==m[i])
      {
     flag++;
       }
    }
    printf("%d        %d\n",a[i],flag);
  }
}

getch();
}
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment