0
0
Cprogramming~10 mins

If 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 the 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 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 age is at least 18.

C
if (age [1] 18) {
    printf("Adult\n");
}
Drag options to blanks, or click blank then click option'
A==
B<=
C>=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '<=' checks for younger ages.
Using '==' only checks if age is exactly 18.
4fill in blank
hard

Fill both blanks to check if a number is between 10 and 20 (inclusive).

C
if (num [1] 10 && num [2] 20) {
    printf("In range\n");
}
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '<=' excludes 20 from the range.
Using '>' instead of '>=' excludes 10 from the range.
5fill in blank
hard

Fill all three blanks to print "Valid" if score is above 50 and below 100.

C
if (score [1] 50 && score [2] 100) {
    printf("[3]\n");
}
Drag options to blanks, or click blank then click option'
A>
B<
C<=
DValid
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' or '<=' changes the range to include 50 or 100.
Printing wrong message or missing quotes.