how to find mean and median by using external functions
Jul 6, 2012 at 6:58am UTC
hello!
i am new in c language can any body tell me how to find mean and median using external functions..
it is a assignment given by our teacher.
plese any budy help me.
Jul 6, 2012 at 7:13am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int mean(int list[], int size)
{
// ...
}
int main()
{
int a[] = {1, 1, 2, 3, 5, 8, 13};
// ...
int m = mean(a, 7);
return 0;
}
Do you anything at all in C or you just want some ideas?
Last edited on Jul 6, 2012 at 7:13am UTC
Jul 6, 2012 at 7:34am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include<iostream>
using namespace std;
double median(double a[], int size)
{
if (size%2 == 0){
double lower = a[size/2];
double upper = a[size/2+1];
return (lower+upper)/2;
}
return a[size/2+1];
}
int main()
{
double a[] = {1,1,2,3,4,8,13};
double median = find_median(a,7);
double mean = find_mean(a,7); //think yourself =)
}
Topic archived. No new replies allowed.