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 number\n"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will check for negative numbers.
Using '==' checks for equality, not positivity.
✗ Incorrect
The condition 'num > 0' checks if the number is positive.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' will check for positive numbers.
Using '==' checks for equality, not negativity.
✗ Incorrect
The condition 'num < 0' checks if the number is negative.
3fill in blank
hardFix 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'
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.
✗ Incorrect
To check if num is zero, use 'num == 0' in the else if condition.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for positivity check.
Using '==' instead of '%' for even check.
✗ Incorrect
First check if num > 0, then use 'num % 2 == 0' to check evenness.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' instead of '>' for positivity check.
Using '!=' instead of '==' for even check.
✗ Incorrect
Check if num > 0, then use 'num % 2 == 0' to check evenness, else non-positive.