0
0
Cprogramming~10 mins

Nested conditional statements - Interactive Code Practice

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 (num [1] 0) {
    printf("Positive number\n");
}
Drag options to blanks, or click blank then click option'
A<
B>
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will check for negative numbers.
Using '==' checks for equality, not positivity.
2fill in blank
medium

Complete the code to check if a number is negative.

C
if (num [1] 0) {
    printf("Negative number\n");
}
Drag options to blanks, or click blank then click option'
A>
B!=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' will check for positive numbers.
Using '==' checks for equality, not negativity.
3fill in blank
hard

Fix the error in the nested if statement to check if a number is zero.

C
if (num > 0) {
    printf("Positive\n");
} else if (num [1] 0) {
    printf("Zero\n");
} else {
    printf("Negative\n");
}
Drag options to blanks, or click blank then click option'
A!=
B<
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' or '<' instead of '==' will not correctly check for zero.
Using '!=' checks for not equal, which is incorrect here.
4fill in blank
hard

Fill both blanks to complete the nested if-else that prints if a number is positive even or odd.

C
if (num [1] 0) {
    if (num [2] 2 == 0) {
        printf("Positive even\n");
    } else {
        printf("Positive odd\n");
    }
}
Drag options to blanks, or click blank then click option'
A>
B<
C%
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for positivity check.
Using '==' instead of '%' for even check.
5fill in blank
hard

Fill all three blanks to complete the nested if-else that categorizes a number as positive even, positive odd, or non-positive.

C
if (num [1] 0) {
    if (num [2] 2 [3] 0) {
        printf("Positive even\n");
    } else {
        printf("Positive odd\n");
    }
} else {
    printf("Non-positive number\n");
}
Drag options to blanks, or click blank then click option'
A>
B%
C==
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' instead of '>' for positivity check.
Using '!=' instead of '==' for even check.