sum,average and standard deviation
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( ).
solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <ctype.h> | |
#include <math.h> | |
#include <stdbool.h> | |
void sum_avg_dev(int data[5],int *sump,double *avgp,double *devp)// accept numbers as array elements and three pointers treated as function output parameters | |
{ | |
for(int i=0;i<5;i++) | |
{ | |
*sump+=data[i];//sum | |
} | |
*avgp=*sump/5.0;//average | |
int sumsqr=0; | |
for(int i=0;i<5;i++) | |
{ | |
sumsqr+=data[i]*data[i]; | |
} | |
*devp=sumsqr/5.0;//std deviation | |
return ; | |
} | |
int main() | |
{ | |
int sum=0; double avge=0.0; double dev=0.0;int array[5]; | |
printf("enter five integers\n"); | |
for(int i=0;i<=4;i++) | |
{ | |
scanf("%d",&array[i]); | |
} | |
sum_avg_dev(array,&sum,&avge,&dev); | |
printf("sum= %d\naverage= %lf\nstandard deviation= %lf\n",sum,avge,dev); | |
return 0; | |
} |
No comments:
Post a Comment