Complete the code to print numbers from 1 to 3 using a for loop.
for(int i = 1; i [1] 3; i++) { printf("%d\n", i); }
The loop should run while i is less than or equal to 3, so it prints 1, 2 and 3.
Complete the code to print a 3x3 grid of stars using nested loops.
for(int i = 0; i < 3; i++) { for(int j = 0; j [1] 3; j++) { printf("*"); } printf("\n"); }
The inner loop should run while j is less than 3 to print 3 stars per line.
Fix the error in the nested loops to correctly print a 4x4 grid of numbers.
for(int row = 1; row <= 4; row++) { for(int col = 1; col [1] 4; col++) { printf("%d ", col); } printf("\n"); }
The inner loop should run while col is less than or equal to 4 to print numbers 1 to 4.
Fill both blanks to create a nested loop that prints a right triangle of stars.
for(int i = 1; i [1] 5; i++) { for(int j = 1; j [2] i; j++) { printf("*"); } printf("\n"); }
Both loops use <= to include the last number and print the correct number of stars per line.
Fill all three blanks to create a nested loop that prints a multiplication table from 1 to 3.
for(int x = 1; x [1] 3; x++) { for(int y = 1; y [2] 3; y++) { printf("%d ", x * [3]); } printf("\n"); }
x instead of y in multiplication will print squares.The loops run from 1 to 3 inclusive, and the multiplication uses y to multiply with x.