Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print numbers from 0 to 4.
C
for (int i = 0; i [1] 5; i++) { printf("%d\n", i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using >= or > will cause the loop to not run as expected.
Using <= will print an extra number.
✗ Incorrect
The loop should run while i is less than 5 to print numbers 0 to 4.
2fill in blank
mediumComplete the code to sum numbers from 1 to 5 using a for loop.
C
int sum = 0; for (int i = 1; i [1] 6; i++) { sum += i; } printf("%d\n", sum);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= 5 instead of < 6 is correct but not in the options.
Using > or >= will cause the loop to not run.
✗ Incorrect
The loop should run while i is less than 6 to include numbers 1 to 5.
3fill in blank
hardFix the error in the for loop condition to print even numbers from 2 to 10.
C
for (int i = 2; i [1] 10; i += 2) { printf("%d\n", i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < 10 will exclude 10 from the output.
Using > or >= will cause the loop to not run.
✗ Incorrect
The loop should run while i is less than or equal to 10 to include 10.
4fill in blank
hardFill both blanks to create a for loop that prints numbers from 10 down to 1.
C
for (int i = [1]; i [2] 1; i--) { printf("%d\n", i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 1 will not print numbers down from 10.
Using > excludes 1 from the output.
✗ Incorrect
The loop starts at 10 and runs while i is greater than or equal to 1.
5fill in blank
hardFill all three blanks to create a for loop that prints squares of numbers from 1 to 5.
C
for (int [1] = 1; [2] [3] 5; [1]++) { printf("%d\n", [1] * [1]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the loop causes errors.
Using < instead of <= excludes 5.
✗ Incorrect
The loop variable is i, and the loop runs while i is less than or equal to 5.