0
0
Cprogramming~10 mins

Why conditional logic is needed - Test Your Understanding

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

Complete the code to check if a number is positive.

C
if ([1] > 0) {
    printf("Positive number\n");
}
Drag options to blanks, or click blank then click option'
Ax
Bnumber
Cvalue
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not declared or used in the code.
2fill in blank
medium

Complete the code to print "Even" if the number is divisible by 2.

C
if ([1] % 2 == 0) {
    printf("Even\n");
}
Drag options to blanks, or click blank then click option'
Avalue
Bnumber
Cx
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable not declared or used in the code snippet.
3fill in blank
hard

Fix the error in the condition to check if age is at least 18.

C
if (age [1] 18) {
    printf("Adult\n");
}
Drag options to blanks, or click blank then click option'
A==
B>
C>=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using == only checks if age is exactly 18, not older.
4fill in blank
hard

Fill both blanks to check if a number is between 10 and 20 (inclusive).

C
if (num [1] 10 && num [2] 20) {
    printf("In range\n");
}
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using < or > excludes boundary values.
5fill in blank
hard

Fill all three blanks to print "Teenager" if age is between 13 and 19 inclusive.

C
if (age [1] 13 && age [2] 19 && age [3] 20) {
    printf("Teenager\n");
}
Drag options to blanks, or click blank then click option'
A>=
B<=
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators that exclude boundary ages.