Bird
0
0
DSA Cprogramming~20 mins

Check if Number is Even or Odd Using Bits in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bitwise Even-Odd Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this code snippet?
Given the code below, what will be printed when the input number is 10?
DSA C
#include <stdio.h>

int main() {
    int num = 10;
    if (num & 1) {
        printf("Odd\n");
    } else {
        printf("Even\n");
    }
    return 0;
}
AEven
BOdd
C10
DCompilation error
Attempts:
2 left
💡 Hint
Check the least significant bit of the number using bitwise AND with 1.
Predict Output
intermediate
2:00remaining
What is the output when num = 7?
Analyze the code below and determine the output when num is 7.
DSA C
#include <stdio.h>

int main() {
    int num = 7;
    if ((num & 1) == 1) {
        printf("Odd\n");
    } else {
        printf("Even\n");
    }
    return 0;
}
ARuntime error
BOdd
C7
DEven
Attempts:
2 left
💡 Hint
The expression (num & 1) checks if the last bit is set.
🧠 Conceptual
advanced
2:00remaining
Why does using bitwise AND with 1 check if a number is even or odd?
Select the best explanation for why the expression (num & 1) can determine if num is even or odd.
ABecause bitwise AND with 1 shifts the number right by one bit.
BBecause it converts the number to its negative equivalent.
CBecause the least significant bit of an odd number is always 1, and for even numbers it is 0.
DBecause it counts the total number of 1 bits in the number.
Attempts:
2 left
💡 Hint
Think about the binary representation of even and odd numbers.
Predict Output
advanced
2:00remaining
What is the output of this code snippet?
What will be printed when the input number is -3?
DSA C
#include <stdio.h>

int main() {
    int num = -3;
    if (num & 1) {
        printf("Odd\n");
    } else {
        printf("Even\n");
    }
    return 0;
}
AOdd
BEven
C0
DUndefined behavior
Attempts:
2 left
💡 Hint
Consider how negative numbers are represented in two's complement.
🔧 Debug
expert
2:00remaining
What error does this code produce?
Identify the error in the following code snippet.
DSA C
#include <stdio.h>

int main() {
    int num = 4;
    if (num & 1 == 1) {
        printf("Odd\n");
    } else {
        printf("Even\n");
    }
    return 0;
}
ARuntime error due to invalid operation
BSyntax error due to missing parentheses
CAlways prints Even regardless of num
DAlways prints Odd regardless of num
Attempts:
2 left
💡 Hint
Check operator precedence between & and ==.