0
0
Cprogramming~10 mins

Loop execution flow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print numbers from 1 to 5 using a for loop.

C
for(int i = 1; i [1] 5; i++) {
    printf("%d\n", i);
}
Drag options to blanks, or click blank then click option'
A>
B<
C<=
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will stop the loop before printing 5.
Using '>' or '>=' will cause the loop to never run.
2fill in blank
medium

Complete the code to sum numbers from 1 to 10 using a while loop.

C
int sum = 0;
int i = 1;
while(i [1] 10) {
    sum += i;
    i++;
}
Drag options to blanks, or click blank then click option'
A>
B<=
C>=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will exclude 10 from the sum.
Using '>' or '>=' will cause the loop to never run.
3fill in blank
hard

Fix the error in the for loop condition to print even numbers from 2 to 10.

C
for(int num = 2; num [1] 10; num += 2) {
    printf("%d\n", num);
}
Drag options to blanks, or click blank then click option'
A<=
B>=
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will exclude 10 from printing.
Using '>' or '>=' will cause the loop to never run.
4fill in blank
hard

Fill 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'
A10
B<=
C>=
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 1 instead of 10.
Using '<=' instead of '>=' in the condition.
5fill in blank
hard

Fill 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'
Ai
C<=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in initialization and condition.
Using '<' instead of '<=' to include 5.