Array Average in C
Level 3119 keystrokes
Calculates and prints the average of an integer array.
C code
// Four values whose average is wanted1int arr[] = {10, 20, 30, 40};// Integer total, starting at 02int sum = 0;// The loop body is the single indented line below3for (int i = 0; i < 4; i++) // After the loop, sum is 1004 sum += arr[i];// Dividing by 4.0 (a double) avoids integer division; %.1f shows one decimal: 25.05printf("Avg: %.1f\n", sum / 4.0);Output
Avg: 25.0
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C code and how often they appear.
;× 6,× 4=× 4+× 3.× 2"× 2(× 2)× 2[× 2]× 2