Complete the code to print numbers from 1 to 5 using a loop.
#include <iostream> int main() { for (int i = 1; i [1] 5; i++) { std::cout << i << std::endl; } return 0; }
The loop should run while i is less than or equal to 5 to print numbers 1 through 5.
Complete the code to sum numbers from 1 to 10 using a loop.
#include <iostream> int main() { int sum = 0; for (int num = 1; num [1] 10; num++) { sum += num; } std::cout << sum << std::endl; return 0; }
The loop should include 10, so use <= to sum numbers from 1 to 10.
Fix the error in the loop condition to print numbers from 0 to 4.
#include <iostream> int main() { for (int i = 0; i [1] 5; i++) { std::cout << i << std::endl; } return 0; }
The loop should run while i is less than 5 to print 0 through 4.
Fill both blanks to create a loop that prints even numbers from 2 to 10.
#include <iostream> int main() { for (int i = [1]; i [2] 10; i += 2) { std::cout << i << std::endl; } return 0; }
Start at 2 and run the loop while i is less than or equal to 10 to print even numbers.
Fill all three blanks to create a loop that prints the squares of numbers from 1 to 5.
#include <iostream> int main() { for (int [1] = 1; [2] [3] 5; [1]++) { std::cout << [1] * [1] << std::endl; } return 0; }
Use i as the loop variable, and run the loop while i is less than or equal to 5 to print squares from 1 to 5.