Wednesday, 1 January 2014

PROGRAM TO FIND MODULE OF ARRAY...!!! (Module: A number which occurs most)

#include<stdio.h>
int main()
{
int array[10]={0};
int x,y,count=0,array1[10]={0},max=0,index;
printf("Enter the elements of array:");
for(x=0;x<10;x++)
{
    scanf("%d",&array[x]);
}
for(x=0;x<10;x++)
{
    count=0;
    for(y=0;y<10;y++)
    {
        if(array[x]==array[y])
        {
            array1[x]++;
        }
    }
}
    for(x=0;x<10;x++)
    {
        if(max<array1[x])
        {
        max=array1[x];
        index=x;
        }
    }
    for(y=0;y<10;y++)
    {
        if (array1[index]==array1[y] && array[index]!=array[y])
        {
            count++;
        }
    }
        if(count>0)
        {
        printf("There is no mode of this array.\n");
        printf("Because more than 1 element occurs most in array ");
        }
        else
        {
        printf("\n%d is mode of array and it is found at %d places",array[index],array1[index]);
        }
getch();
return 0;
}


EXPECTED OUTPUTS:

Note: You can change the elements of array and get results according to your choice...!!!




No comments:

Post a Comment