0
0
Cprogramming~10 mins

If–else statement 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 '<' instead of '>' will check for negative numbers.
Using '==' checks for equality, not positivity.
2fill in blank
medium

Complete the code to print "Even" if the number is even.

C
if (num % 2 [1] 0) {
    printf("Even\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 odd numbers instead.
Using '>' or '<' does not correctly check for evenness.
3fill in blank
hard

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

C
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 instead.
Using '==' checks for zero, not negativity.
4fill in blank
hard

Fill both blanks to complete the if-else statement that prints if a number is positive or not.

C
if (num [1] 0) {
    printf("Positive\n");
} else {
    printf("[2]\n");
}
Drag options to blanks, or click blank then click option'
A>
BNegative
CZero
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' in the first blank reverses the logic.
Printing 'Zero' instead of 'Negative' changes the meaning.
5fill in blank
hard

Fill all three blanks to complete the if-else if-else statement that checks if a number is positive, zero, or negative.

C
if (num [1] 0) {
    printf("Positive\n");
} else if (num [2] 0) {
    printf("Zero\n");
} else {
    printf("[3]\n");
}
Drag options to blanks, or click blank then click option'
A>
B==
CNegative
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up comparison operators.
Printing wrong labels for conditions.