While Loop Product in C
Level 286 keystrokes
Uses a while loop to multiply the numbers 1 through 4 together, which is 4 factorial, and prints 24.
C code
// n is the counter; product starts at 1, not 0, because multiplying by 0 would always give 01int n = 1, product = 1;// Repeats for n = 1, 2, 3 and 42while (n <= 4) { // Multiplies the running product by n: 1, 2, 6, then 243 product *= n; // Moves to the next number; the loop ends when n becomes 54 n++;5}// Prints the product 1 * 2 * 3 * 4, which is 246printf("%d\n", product);Output
24
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.
;× 4=× 4,× 2"× 2(× 2)× 2+× 2{× 1}× 1*× 1