Friday, October 30, 2009

Sum,Average Standard deviation 5[F]b

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

void main()
{
float ave,sd;
int a,b,c,d,e,sum;
printf("\nInput 5 integers");
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
func(a,b,c,d,e,&sum,&ave,&sd);
printf("\nThe sum is %d\nThe average is %f\nThe standard deviation is %f",sum,ave,sd);
}

func(int a,int b,int c,int d,int e,int *su,float *av,float *std)
{
*su=a+b+c+d+e;
*av=*su/5;
*std=sqrt((((a-*av)*(a-*av))+((b-*av)*(b-*av))+((c-*av)*(c-*av)))/5.0);
}

No comments:

Post a Comment