Complete the code to print numbers from 1 to 5 using a loop.
#include <stdio.h> int main() { int i = 1; while ([1] <= 5) { printf("%d\n", i); i++; } return 0; }
The variable i is used to control the loop and print numbers from 1 to 5.
Complete the code to sum numbers from 1 to 10 using a for loop.
#include <stdio.h> int main() { int sum = 0; for (int i = 1; i [1] 10; i++) { sum += i; } printf("Sum is %d\n", sum); return 0; }
The loop should include 10, so the condition uses <= to go up to 10.
Fix the error in the loop condition to print numbers from 0 to 4.
#include <stdio.h> int main() { int count = 0; while (count [1] 5) { printf("%d\n", count); count++; } return 0; }
The loop should run while count is less than 5 to print 0 to 4.
Fill both blanks to create a loop that prints even numbers from 2 to 10.
#include <stdio.h> int main() { for (int num = [1]; num [2] 10; num += 2) { printf("%d\n", num); } return 0; }
The loop starts at 2 and runs while num is less than or equal to 10 to print even numbers.
Fill all three blanks to create a loop that prints numbers from 5 down to 1.
#include <stdio.h> int main() { for (int i = [1]; i [2] 1; i[3]) { printf("%d\n", i); } return 0; }
The loop starts at 5, runs while i is greater than or equal to 1, and decreases i by 1 each time.
