Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will check for negative numbers.
Using '==' checks only if number equals zero.
✗ Incorrect
The condition num > 0 checks if the number is positive.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' causes assignment, not comparison.
Using '!=' checks for not equal, which is incorrect here.
✗ Incorrect
The condition num == 0 checks if the number is exactly zero.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' checks for positive numbers, not negative.
Using '==' checks for zero, not negative numbers.
✗ Incorrect
The condition num < 0 correctly checks if the number is negative.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the operators will give wrong results.
Using '==' in these conditions is incorrect.
✗ Incorrect
The first condition checks if num > 0 (positive), the second if num < 0 (negative), else zero.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' for zero check.
Mixing up the order of conditions.
✗ Incorrect
The conditions check if num > 0 (positive), num < 0 (negative), and num == 0 (zero).