Monday, March 26, 2012

Program to count the mode of a series


/*****************<soeasyprograms.blogspot.in>******************/
/*Program to count the mode of a series*/


#include<stdio.h>
#include<conio.h>


void main()
{
int i,j,k=1,p,a[20],b[20],n,cnt=1,big;
clrscr();
printf("Enter the maximum number of elements\n");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=1; i<=n; i++)
scanf("%d",&a[i]);
for(i=1; i<=n; i++)
{
 for(j=i+1;j<=n; j++)
 {
  if(a[i]==a[j])
  cnt++;           /*no of time the element occur*/
 }
 b[k]=cnt;
 k++;
 cnt=1;
}


big=b[1];
p=1;
for(i=2; i<=n; i++)
{
 if(big<b[i])
 {
   big=b[i];
   p=i;
 }


}
printf("The Mode of given series is %d\n",a[p]);
printf("And it has occurred %d times\n",b[p]);
getch();
}
/*****************<soeasyprograms.blogspot.in>******************/

No comments:

Post a Comment