Average the items in a 5 element array
#include <stdio.h>
int main() {
float data[5];
float total;
float average;
data[0] = 3.0;
data[1] = 2.0;
data[2] = 4.0;
data[3] = 8.0;
data[4] = 2.0;
total = data[0] + data[1] + data[2] + data[3] + data[4];
average = total / 5.0;
printf("Total %f Average %f\n", total, average);
return (0);
}
Related examples in the same category