Sunday, November 21, 2010

Write a C program to find following parameters for known 3 numbers. a. Sum b. Average c. Min d. Max e. Variance f. Standard deviation

#include
#include
float Sum(float a, float b, float c);
float Avg(float a, float b, float c);
float Min(float a, float b);
float Max(float a, float b);
float Vari(float a, float b, float c);
float SD(float a, float b, float c);
float input(float temp);

int main()
{
float a,b,c;

printf("Enter 'a' value: ");
a = input(a);

printf("Enter 'b' value: ");
b = input(b);

printf("Enter 'c' value: ");
c = input(c);

printf("\nSum of %.1f, %.1f and %.1f = %.1f\n",a,b,c,Sum(a,b,c));
printf("Avg of %.1f, %.1f and %.1f = %.1f\n",a,b,c,Avg(a,b,c));
printf("Min of %.1f, %.1f and %.1f = %.1f\n",a,b,c,Min(Min(a,b),c));
printf("Max of %.1f, %.1f and %.1f = %.1f\n",a,b,c,Max(Max(a,b),c));
printf("\nVariance of %.1f, %.1f and %.1f = %.1f\n",a,b,c,Vari(a,b,c));
printf("Standard deviation of %.1f, %.1f and %.1f = %.1f\n",a,b,c,SD(a,b,c));

return 0;
}
float input(float temp)
{
scanf("%f",&temp);
return temp;
}
float Sum(float a, float b, float c)
{
return (a+b+c);
}
float Avg(float a, float b, float c)
{
return (Sum(a,b,c)/3);
}
float Min(float a, float b)
{
float x;
x = (a <= b) ? a : b; return x; } float Max(float a, float b) { float x; x = (a >= b) ? a : b;
return x;
}
float Vari(float a, float b, float c)
{
float x,y,z;
x = pow((a - Avg(a,b,c)),2);
y = pow((b - Avg(a,b,c)),2);
z = pow((c - Avg(a,b,c)),2);

return Avg(x,y,z);
}
float SD(float a, float b, float c)
{
return sqrt(Vari(a,b,c));
}