Calculate the average

#include "stdio.h" #include "stdlib.h" double calculateAverage(int); double* addNumers(int); int main(int argc, char const *argv[]) { int times = 0; printf("How many numbers are to calculate the average?\n"); scanf("%d",&times); printf("The average is: %f\n",calculateAverage(times)); return 0; } double* addNumers(int times){ double *average = (double*)calloc(2,sizeof(double)); do { printf("Put a number\n"); scanf("%lf",&average[0]); times--; average[1] += average[0]; } while (times > 0); return average; } double calculateAverage(int times){ return addNumers(times)[1]/times; }
Calculate the average by using just two variables

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.