0
0
Cprogramming~10 mins

Switch vs if comparison - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print "One" when variable x equals 1 using if statement.

C
if (x [1] 1) {
    printf("One\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.
2fill in blank
medium

Complete the switch statement to handle the case when variable c equals 'a'.

C
switch(c) {
    case [1]:
        printf("Letter a\n");
        break;
}
Drag options to blanks, or click blank then click option'
A'b'
B'a'
C'c'
D'd'
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes instead of single quotes for characters.
3fill in blank
hard

Fix the error in the if statement condition to correctly check if n is not equal to 0.

C
if (n [1] 0) {
    printf("Non-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.
4fill in blank
hard

Fill both blanks to complete the switch statement that prints "Weekend" for 6 or 7.

C
switch(day) {
    case [1]:
    case [2]:
        printf("Weekend\n");
        break;
}
Drag options to blanks, or click blank then click option'
A6
B5
C7
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong case numbers for weekend days.
5fill in blank
hard

Fill all three blanks to complete the if-else chain that prints the day type based on day number.

C
if (day [1] 6 || day [2] 7) {
    printf("Weekend\n");
} else if (day [3] 1 && day <= 5) {
    printf("Weekday\n");
}
Drag options to blanks, or click blank then click option'
A==
B>=
C<=
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong logical operators or comparison signs.