answersLogoWhite

0


Best Answer

#include<stdio.h>

#define MAXVAL 1000

void sort1(int a[],int n);

void median(int a[],int n);

void mode(int a[],int n);

int main()

{

int n;

int arr[MAXVAL];

int i;

printf("Enter the number of elements:");

scanf("%d",&n);

printf("Enter the values:");

for(i=0;i<n;i++)

{

printf("a[%d]=",i);

scanf("%d",&arr[i]);

}

sort1(arr,n);

median(arr,n);

mode(arr,n);

}

void sort1(int a[],int n)

{

int i;

int j;

int temp;

for(i=0;i<n;i++)

{

for(j=i;j<n;j++)

{

if(a[i]>a[j])

{

temp=a[i];

a[i]=a[j];

a[j]=temp;

}

}

}

}

void median(int a[],int n)

{

int median;

int mid;

if((n%2)==0)

{

mid=n/2;

median=(a[mid-1]+a[mid])/2;

}

else

{

mid=(n+1)/2;

median=a[mid-1];

}

printf("The median is:%d\n",median);

}

void mode(int a[],int n)

{

int i;

int count1[MAXVAL];

for(i=0;i<n;i++)

{

count1[i]=0;

}

for(i=0;i<n;i++)

{

count1[a[i]]++;

}

i--;

int mode=count1[0];

int j;

int k;

int flag=0;

for(j=0;j<=a[i];j++)

{

if(count1[j]>count1[mode])

mode=j;

}

for(j=0;j<=a[i];j++)

{

for(k=j+1;k<=a[i];k++)

{

if(count1[j]=count1[k] && count1[j]>count1[mode])

{

flag=1;

}

}

}

if(flag==1)

{

printf("Mode cannot be calculated");

}

else

printf("the Mode is:%d",mode);

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c program to print mean median and mode?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Can the mean be smaller than the median for a set of data?

Yes. If the lower values tend to be farther below the median than the highest values are above the median, the mean is smaller than the median. why are write wrong


How do mean deviation from median?

The mean deviation from the median is equal to the mean minus the median.


C program to find the mean median mode?

try this---&gt; http://c-pgms.blogspot.com/2008/08/program-to-find-meanmedianand-mode_22.html


What is the median of 65 and 90?

The median of 65 and 90 is the same as their mean: 77.5The median of 65 and 90 is the same as their mean: 77.5The median of 65 and 90 is the same as their mean: 77.5The median of 65 and 90 is the same as their mean: 77.5


Who discovered the mean median and mode?

who discovered mean median and mode


Mean median and?

Mean, Median and Mode. They are three kinds of averages.


What is the definition of mean and median in math?

Mean is the average, and median is the middle number.


Can ypu find the mean and median with data from a histogram?

You can estimate the median and the mean.


How does the outlier affect the mean and median?

The mean is better than the median when there are outliers.


What is the median of 4 numbers?

To find the median of a set of numbers write them in order, then: * if there are an odd number of numbers then the median is the number in the middle * otherwise there are an even number of numbers and the median is the mean average of the two numbers in the middle. With 4 numbers there is an even number of numbers, so the median is the mean average of the 2nd and 3rd numbers when they are sorted into order. Example: Find median of {3, 9, 4, 5} Ordered &rarr; {3, 4, 5, 9} &rarr; median = mean_average(4, 5) = (4 + 5) &divide; 2 = 4.5


How does the mean compare to the median?

The mean and the median are both involved with a set of numbers. The mean refers to the average of the numbers. The median refers to the middle number of the numbers


How do you compare median to the mean in this set 10 8 8 8 4 6 9 3?

median = 8 mean = 7 mean &lt; median.