Plain C Average
#include <stdio.h> int main() { // Read the numbers. int n1, n2, n3; printf("Enter Three Integers: "); scanf("%d %d %d", &n1, &n2, &n3); // Compute the sum and average. double sum = n1 + n2 + n3; printf("Mean %d %d %d is %f\n", n1, n2, n3, sum/3.0); return 0; }

The scanf and printf functions are part of stdio.h. Use scanf for input, and printf to print. The %d constructs in the print strings convert variables from the list, in the same order. The letter gives the type. The %d reads or prints a decimal integer, while the %f converts a floating point value.

Notice that, for input, the variables are given with an ampersand: as &n1 instead of just the n1 needed to print. We're not ready to explain this. For now, just note that it allows the function to set the value of the variable; without, the function can only read it.

[more info]