C Even Number Program

Beginner
5 min read
Updated: Oct 2026
3 programs
Live preview

What Is an Even Number?

An even number is an integer divisible by 2 with remainder 0. In math form: n = 2 * k for some integer k.

Remember
n is even  ↔  n % 2 == 0

Examples:
  10 % 2 == 0  → even
  11 % 2 == 1  → odd
   0 % 2 == 0  → even
  -4 % 2 == 0  → even
nn % 2Result
100Even
111Odd
00Even
-40Even

How to Check an Even Number in C

Four clear steps — then pick modulo, bitwise, or a step-by-two range loop.

  1. Read the integer n (positive, negative, or zero).
  2. Compute n % 2 (or check the least significant bit with n & 1).
  3. If the remainder is 0 (or the LSB is 0), n is even.
  4. To list evens in a range, test each value — or start at the first even and add 2.
MethodIdeaTimeBest for
Modulon % 2 == 0O(1)Interviews, clearest logic
Bitwise(n & 1) == 0O(1)Optional follow-up, LSB check
Step by 2Start at first even, add 2O(N/2)Listing evens in a range

Pseudocode

Pseudocode
function IsEven(n):
    return (n mod 2) == 0

function PrintEvens(start, end):
    for i from start to end:
        if IsEven(i):
            output i

// Faster range listing:
function PrintEvensStep(start, end):
    i = start
    if i is odd:
        i = i + 1
    while i <= end:
        output i
        i = i + 2

Cheat Sheet

Keep these facts handy while writing the program.

TopicDetail
Even testn % 2 == 0
Odd testn % 2 != 0
Bitwise even(n & 1) == 0
Zero0 is even
Negatives-4 is even; -3 is odd
Classic check10 → even; 11 → odd

Live Preview

Enter any integer to see the remainder and the even/odd verdict.

Whole numbers only. Tap a chip or type a value.

Result
n = 10
n % 2 = 0
(n & 1) = 0
Verdict: EVEN

Worked Walkthrough — n = 10

Apply the modulo rule, then confirm with the bitwise check.

Calculation
Step 1: Compute 10 % 2
        10 = 2 * 5 + 0
        remainder = 0

Step 2: Remainder is 0 → even

Step 3: Bitwise check
        10 in binary ends with 0
        (10 & 1) = 0 → same answer

Verdict: 10 is even

C Programs

Start with the modulo helper — it is the clearest interview answer. Then reuse it for a range, and finish with the bitwise shortcut.

Example 1 — Modulo Check

Return true when the remainder by 2 is exactly zero.

C
#include <stdio.h>

int is_even(int n)
{
    return n % 2 == 0;
}

int main(void)
{
    int number = 10;
    if (is_even(number))
        printf("%d is an even number.\n", number);
    else
        printf("%d is not an even number.\n", number);
    return 0;
}

How It Works

  1. is_even computes n % 2 and compares it with 0.
  2. For 10, the remainder is 0, so the function returns true (nonzero).
  3. main prints the matching message based on that result.
  4. Swap 10 for 11 to see the odd path.
  5. This is the default answer to give in interviews — clear and correct.

Example 2 — Evens in a Range

Reuse the helper to print every even value from 1 to 10.

C
#include <stdio.h>

int is_even(int n)
{
    return n % 2 == 0;
}

int main(void)
{
    int start = 1;
    int end = 10;
    int i;

    printf("Even numbers from %d to %d:\n", start, end);
    for (i = start; i <= end; i++)
    {
        if (is_even(i))
            printf("%d ", i);
    }
    printf("\n");
    return 0;
}

How It Works

  1. The loop runs from start to end inclusive (i <= end).
  2. Each i is tested with is_even.
  3. Only even values are printed: 2 4 6 8 10.
  4. Odd values like 1, 3, and 5 are skipped.
  5. For large ranges, start at the first even and use i += 2 instead of testing every integer.

Example 3 — Bitwise Check

Even integers have a least significant bit of 0, so n & 1 is 0.

C
#include <stdio.h>

int is_even_bitwise(int n)
{
    return (n & 1) == 0;
}

int main(void)
{
    int samples[] = { 10, 11, 0, -4 };
    int i;

    for (i = 0; i < 4; i++)
    {
        int n = samples[i];
        printf("%d: %s\n", n, is_even_bitwise(n) ? "even" : "odd");
    }
    return 0;
}

How It Works

  1. n & 1 keeps only the least significant bit.
  2. If that bit is 0, the number is even; if 1, it is odd.
  3. The sample array shows positives, zero, and a negative even value.
  4. Results match the modulo method for these integers.
  5. Prefer modulo in interviews for readability; mention bitwise as a follow-up.

Edge Cases & Pitfalls

Check these before calling the solution done.

Zero

0 is even

0 % 2 == 0. Do not special-case zero as “neither.”

Negatives

Parity still applies

-4 is even. Odd negatives can give -1 with % — still nonzero, so still odd.

Floats

Use integers

Even/odd is defined for integers. Do not apply % 2 to floating-point “counts” without a clear rule.

Range

Inclusive bounds

Use i <= end when both ends should be checked. Off-by-one errors drop the last even.

Time and Space Complexity

ProgramTimeExtra space
Modulo / bitwise checkO(1)O(1)
Scan range of size NO(N)O(1)
Step-by-two listingO(N/2)O(1)

A single parity test is constant time. Range printers grow with how many integers you visit.

Key Takeaways

  • Definition: divisible by 2 with remainder 0 (n = 2k).
  • Default test: n % 2 == 0.
  • Bitwise option: (n & 1) == 0.
  • Test set: 10 even; 11 odd; 0 even; −4 even.

One line: if n % 2 == 0, the integer is even — including zero and many negatives.

Frequently Asked Questions

An integer n is even if n = 2 * k for some integer k. Equivalently, n is divisible by 2 with remainder 0.
Use n % 2 == 0 for the clearest test. You can also use (n & 1) == 0 as a bitwise shortcut.
Yes. 0 = 2 * 0, so 0 % 2 == 0 and zero is even.
Yes. -4 is even. In C (C99+), -4 % 2 == 0. Prefer (n & 1) == 0 if you want one rule that also avoids odd-negative remainder quirks.
Checking one number is O(1). Scanning a range of size N is O(N), or O(N/2) if you start at the first even and step by 2.

Next: Evil Number

Check whether the binary form has an even count of 1-bits.

Evil number tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful