Here's a simple program that is to be used for calculating Sum, Average and Standard Deviation.

But it doesn't work. There's a problem with the sqrt function. I hear it returns a double value. But then there will be a pointer problem I guess. Pointer variables have to be int. (just guessing)

Here's the program:

Code:

/*
Write a function that receives 5 integers and returns the sum, average and standard
deviation of these numbers. Call this function from main() and print the results in main().
*/
#include<stdio.h>
#include<math.h>
main()
{
int a, b, c, d, e, sum, avg, sd;
int calc (int a, int b, int c, int d, int e, int *sum, int *avg,int *sd);
printf("Enter Five Numbers:");
scanf ("%d %d %d %d %d", &a, &b, &c, &d, &e);
calc (a, b, c, d, e, &sum, &avg, &sd);
printf("Sum=%d", sum);
printf("Average=%d", avg);
printf("Standard Deviation=%lf", sd);
}
calc (int a, int b, int c, int d, int e, int *sum, int *avg, int *sd)
{
int calc_sd;
*sum=a+b+c+d+e;
*avg=(a+b+c+d+e)/5;
/*To calculate Standard Deviation, first we have to calculate
the mean average. Here n=5 .. Five Numbers and then calculate
Standard Deviation by this formula:
sqrt(((x1-mean)(x2-mean)....(xn-mean))/total numbers)*/
calc_sd = ((a- *avg)*(b- *avg)*(c-*avg)*(d-*avg)*(e-*avg))/5;
*sd= sqrt(calc_sd); //sqrt function must have only one variable in those braces. :(
}

Also, one more thing...

I used GCC, and the program won't compile on it.

It gave me warning / errors I never knew.

But then I tried MS Visual C++ IDE..it gives me warnings and the program compiles fine.

Except that the Standard Deviation thing doesn't work out properly..

So is it like GCC won't compile the programs if there are warnings?