For Loop Product in C++
Level 288 keystrokes
Multiplies the numbers 1 to 5 together in a for loop to compute 5! (the factorial of 5) and prints 120.
C++ code
// Starts at 1, because starting at 0 would make every product 01int product = 1;// i takes the values 1, 2, 3, 4 and 52for (int i = 1; i <= 5; i++) { // Multiplies product by i: 1, 2, 6, 24, 1203 product *= i;4}// Prints 5! = 1205cout << product << endl;Output
120
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<× 5=× 4+× 2(× 1)× 1{× 1}× 1*× 1