Bird
0
0
DSA Cprogramming~10 mins

Check if Number is Even or Odd Using Bits in DSA C - Interactive 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 even using bitwise AND.

DSA C
if ((num & [1]) == 0) {
    printf("Even\n");
} else {
    printf("Odd\n");
}
Drag options to blanks, or click blank then click option'
A2
B0
Cnum
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as mask always results in zero.
Using 2 checks the wrong bit.
Using the number itself as mask is incorrect.
2fill in blank
medium

Complete the code to print "Odd" when the number is odd using bitwise operation.

DSA C
if ((num & [1]) != 0) {
    printf("Odd\n");
} else {
    printf("Even\n");
}
Drag options to blanks, or click blank then click option'
A1
B0
C2
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as mask always results in zero.
Using 2 checks the wrong bit.
Using the number itself as mask is incorrect.
3fill in blank
hard

Fix the error in the code to correctly check if a number is even using bitwise operation.

DSA C
if ((num [1] 1) == 0) {
    printf("Even\n");
} else {
    printf("Odd\n");
}
Drag options to blanks, or click blank then click option'
A&
B|
C^
D<<
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise OR (|) instead of AND.
Using XOR (^) which toggles bits.
Using shift operators (<<) incorrectly.
4fill in blank
hard

Fill both blanks to complete the function that returns 1 if number is even, else 0.

DSA C
int isEven(int num) {
    return (num [1] 1) [2] 0;
}
Drag options to blanks, or click blank then click option'
A&
B==
C!=
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR instead of AND.
Using != instead of == for comparison.
5fill in blank
hard

Fill all three blanks to complete the code that prints if a number is even or odd using bitwise operations.

DSA C
int num = 7;
if ((num [1] [2]) [3] 0) {
    printf("Odd\n");
} else {
    printf("Even\n");
}
Drag options to blanks, or click blank then click option'
A&
B1
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of != causes wrong output.
Using | instead of & changes logic.