For Loop Sum in C
Level 276 keystrokes
Uses a for loop to add the numbers 1 through 5 into sum and prints the total, 15.
C code
// sum must start at 0 before anything is added to it1int sum = 0;// i takes the values 1, 2, 3, 4 and 52for (int i = 1; i <= 5; i++) { // Adds the current i to the running total3 sum += i;4}// After the loop sum is 1 + 2 + 3 + 4 + 5 = 15, which is printed5printf("%d\n", sum);Output
15
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.
;× 5=× 4+× 3"× 2(× 2)× 2,× 1{× 1}× 1\× 1