## Program to find Mean,Median,and Mode

/***************************************************************

******* Program to find Mean,Median,and Mode *******

****************************************************************/

#define SIZE 100

#include<stdio.h>

float mean_function(float[],int);

float median_function(float[],int);

float mode_function(float[],int);

int main()

{

int i,n,choice;

float array[SIZE],mean,median,mode;

printf("Enter No of Elements\n");

scanf("%d",&n);

printf("Enter Elements\n");

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

scanf("%f",&array[i]);

do

{

printf("\n\tEnter Choice\n\t1.Mean\n\t2.Median\n\t3.Mode\n4.Exit");

scanf("%d",&choice);

switch(choice)

{

case 1:

mean=mean_function(array,n);

printf("\n\tMean = %f\n",mean);

break;

case 2:

median=median_function(array,n);

printf("\n\tMedian = %f\n",median);

break;

case 3:

mode=mode_function(array,n);

printf("\n\tMode = %f\n",mode);

break;

case 4:

break;

default:

printf("Wrong Option");

break;

}

}while(choice!=4);

}

/***************************************************************

Function Name : mean_function

Purpose : to find mean

Input : array of elements,no of elements

Return Value : Mean

Return Type : Float

****************************************************************/

float mean_function(float array[],int n)

{

int i;

float sum=0;

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

sum=sum+array[i];

return (sum/n);

}

/***************************************************************

Function Name : median_function

Purpose : to find median

Input : array of elements,no of elements

Return Value : Median

Return Type : Float

****************************************************************/

float median_function(float a[],int n)

{

float temp;

int i,j;

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

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

{

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

{

temp=a[j];

a[j]=a[i];

a[i]=temp;

}

}

if(n%2==0)

return (a[n/2]+a[n/2-1])/2;

else

return a[n/2];

}

float mode_function(float a[],int n)

{

return (3*median_function(a,n)-2*mean_function(a,n));

}

Output

————–

Enter Elements

2

3

4

Enter Choice

1.Mean

2.Median

3.Mode

4.Exit

1

Mean = 3.000000

Enter Choice

1.Mean

2.Median

3.Mode

4.Exit

2

Median = 3.000000

Enter Choice

1.Mean

2.Median

3.Mode

4.Exit

3

Mode = 3.000000

Enter Choice

1.Mean

2.Median

3.Mode

4.Exit

4

——————-

Enter No of Elements

4

Enter Elements

9 8 7 6

Enter Choice

1.Mean

2.Median

3.Mode

4.Exit

1

Mean = 7.500000

Enter Choice

1.Mean

2.Median

3.Mode

4.Exit

2

Median = 7.500000

Enter Choice

1.Mean

2.Median

3.Mode

4.Exit

3

Mode = 7.500000

Enter Choice

1.Mean

2.Median

3.Mode

4.Exit

4

Keys : program to find mean, program to find median, program to find mode, mean median mode program, program to find mean median mode, find the median, finding the median and mode, c programming median, "find mode" array median, find mode, array median,median program in c, c program finding mode of a list, c program on mean median and mode, program to find mean median and mode, mean median c programming, how to find the median, median in c programming.

Program to find Mean,Median,and Mode,
i wanted a program to find mean, median and mode WITHOUT using switch function!!!!!!!! its a nice program but i think its DULL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

make just a simple but correct program to find something….. dont just make it look like very complicated because of just adding nonsense codes!!!!!! make it easy to understand!!!!!!!

Nice program, though shouldn’t the mode be the most frequent number?

Nica and easy program………this program totally help me to complete my project……

saya pengen tahu yang jelas tentang contoh code programnya bisa tidak di cantumkan,terimakasih sebelumnya ^^

the mode is wrong.

how about the mode???

@j

Can you tell me what is the problem?

Nice and elegant program. Mr. Jishnu, mind if I use this source code for a project we have in college ????

sure you can.

you are a very good programmer.

thanks to you.

can you write program for insertion,deletion an element from stack,queue using singly linked list.

please help me.

mustak,here is the program for stack using linked list http://thecodecracker.com/c-programming/implementation-of-stack-using-linked-list/

and here is the que using linked list http://thecodecracker.com/c-programming/queue-operations-using-linked-list/

Your median is completely wrong. It only works if you have the numbers in order from least to greatest. Other than that it fails every other time

@Steve,

are you sure ?

can you post your output ?

Here is my output (not in the least to greatest order as you said)

Enter No of Elements

4

Enter Elements

6

4

4

1

Enter Choice

1.Mean

2.Median

3.Mode

4.Exit2

Median = 4.000000

hai jishnu

can i ask one questain.pls give me a answer.how u get the logic to do like this.

i’am also a mca student butI can’t pls answer me pls pls pls

Hi! I am shan. I am working in a school[Teacher].

I need perfect answer and also that Short answer type in “C-Program”. Becoz, the pupils have not more capacity about this “C-Program”. Becoz, this is the foundation. So plz provide a very short type program about “Related Important All Program”. So don’t mistaken me. This is my “KIND” request. —> By Shanthi

i didn’t understand what u mean..

Write a C++ program that will compute the mean, median, mode of a given data

I just want to run a program that shows me the median betwhin 3 integer numbers, I wrote it but it doesnt work. here it is: what do yo you think about it?

#include

using namespace std;

int main()

{

long int a,b,c,med;

cout<<"please enter 3 integer numbers:";

if ((a-b)*(a-c)<0)

{

med=a;

}

if ((b-a)*(b-c)<0)

{

med=b;

}

if ((c-a)*(c-b)<0)

{

med=c;

}

cout<<"median="<<"med"<<endl;

return 0;

}

I’ve been surfing a lot this night and I’m glad that I landed on your page for out of all the program your’s is the only one who would run and I’m not exaggerating.

Thank you so much for sharing this code, really

yeah this is very helpful for the students of grade 8&9 for getting knowledge about the basic programing. superb work keep it up.

Hey Dude.. The Mode is Wrong..It is showing wrong answer.. Other than that the Programming is Good.

Good Progamming.. Just try to correct that..ok

this program was very nice but iwant to simple program of mean,mode, mdian

Mode is wrong. Try checking out the definition of mode(statistics)

Here is my code…. It is a bit long but I know you can get it :). It is long but very good. It gives you bimode, trimode…all the modes (in case there is more than one mode).

For example.

2,3,4,4,2 … the mode is = 2,4

and

3,3,4,4 does not have a mode because all the modes are the same.

the String parameter for this method must be like this “2,3,4,2,23,234,21,123,34″

It organices the numbers and gives you all the info!

public String calcularEnOrden2(String numeros){

int modeCount =0;

ArrayList integers = new ArrayList();

int repeatedCounter=0;

String[] numbers0 = numeros.split(“,”);

int[] numbers = new int[numbers0.length];

for(int x=0; x<numbers.length;x++){

numbers[x]= Integer.parseInt(numbers0[x]);

}

int[] numbersP = new int[numbers.length];

for(int i=0; i<numbers.length;i++){

int timesRepeatedInTheArray =0;

int biggerThanHowManyNumbersInTheArray = 0;

for(int j=0; jnumbers[j]){

biggerThanHowManyNumbersInTheArray++;

}

}

if(repeatedCounter<timesRepeatedInTheArray){

if(repeatedCounter!=0){

integers.clear();

integers.add(numbers[i]+"");

}

repeatedCounter = timesRepeatedInTheArray;

}

else if(repeatedCounter == timesRepeatedInTheArray){

boolean iBangYourWife = true;

modeCount++;

for(int y=0; y<integers.size();y++){

if(Integer.parseInt(integers.get(y)) == numbers[i]){

iBangYourWife = false; //

}

}

if(iBangYourWife){

integers.add(numbers[i]+"");

}

}

//This is how I organize numbers from smaller to bigger. You should analyze it with pencil and paper, it is very useful for the future.

int counter = timesRepeatedInTheArray;

for(int m=biggerThanHowManyNumbersInTheArray; m<numbers.length;m++){

if(counter != 0){

numbersP[m] = numbers[i];

counter–;

}

}

}

int length = numbersP.length;

double medianA=0;

double contador = numbersP.length;

double numberPValuesTotalSum = 0;

String respuesta= "";

for(int h=0; h<numbersP.length;h++){

respuesta = respuesta + " " + numbersP[h];

numberPValuesTotalSum = numberPValuesTotalSum + numbersP[h];

}

if(numbersP.length%2 !=0){

Double median0 = ((numbersP.length/2) – 0.5);

medianA = numbersP[median0.intValue()];

}

else{

medianA = ((numbersP[length/2] + numbersP[(length/2)-1])/2.0);

}

String modes="";

if(modeCount == numbers.length-1){

modes ="No existing modes";

}

else{

for(int l=0;l<integers.size();l++){

if(l==0){

modes =integers.get(l);

}

else{

modes = modes + ", " + integers.get(l);

}

}

}

double totalMean = numberPValuesTotalSum/contador;

String final2 = "Smaller to Bigger: \n"+

respuesta+"\n"+

"Mean: \n"

+totalMean+"\n"+

"Median:\n"+

+medianA+"\n"+

"Mode: \n"

+modes+"";

return final2;

}