0
0
Cprogramming~10 mins

Else–if ladder in C - 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\n");
}
Drag options to blanks, or click blank then click option'
A<
B!=
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will check for negative numbers.
Using '==' checks only if number equals zero.
2fill in blank
medium

Complete the else-if ladder to check if a number is zero.

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

Fix the error in the else-if ladder condition to check if a number is negative.

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

Fill both blanks to complete the else-if ladder that prints the sign of a number.

C
if (num [1] 0) {
    printf("Positive\n");
} else if (num [2] 0) {
    printf("Negative\n");
} else {
    printf("Zero\n");
}
Drag options to blanks, or click blank then click option'
A>
B<
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the operators will give wrong results.
Using '==' in these conditions is incorrect.
5fill in blank
hard

Fill all three blanks to complete the else-if ladder that categorizes a number.

C
if (num [1] 0) {
    printf("Positive\n");
} else if (num [2] 0) {
    printf("Negative\n");
} else if (num [3] 0) {
    printf("Zero\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 zero check.
Mixing up the order of conditions.