Where knowledge empowers you to understand your world

Sample Code: Averaging Numbers In C

A simple code example that averages numbers in the C programming language.

#include <stdio.h>

int main(void) {
int c;
int i;
float avgtemp;
float temperature[10]; 

for (c=0; c < 10; c++) {
    printf("Enter The Temperature: ");
    scanf("%f", &temperature[c]); 
}

if (c==10) {
	for(i = 0; i < 10; i++) {
	    avgtemp = avgtemp + temperature[i];
	}
	avgtemp = avgtemp / 10;
	printf("%f", avgtemp);
}

return 0;

}

Leave a Reply