Even Odd Program in Python, C, C++, Java [Beginner Guide]

Introduction

Checking whether a number is even or odd is one of the most common beginner coding problems. It helps you understand conditional statements, input/output handling, and the modulus operator.

If you’re just starting with coding, make sure you also check out our guide on Factorial Program in Python and Fibonacci Series in C++.


Logic Behind Even Odd Program

A number is:

  • Even if divisible by 2 (num % 2 == 0)
  • Odd if not divisible by 2 (num % 2 != 0)

Mathematically:

if num % 2 == 0:
    Even
else:
    Odd

Even Odd Program in Python

# Even Odd Program in Python

num = int(input("Enter a number: "))

if num % 2 == 0:
    print(f"{num} is Even")
else:
    print(f"{num} is Odd")

Even Odd Program in C

#include <stdio.h>

int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);

if (num % 2 == 0)
printf("%d is Even\n", num);
else
printf("%d is Odd\n", num);

return 0;
}

Even Odd Program in C++

#include <iostream>
using namespace std;

int main() {
    int num;
    cout << "Enter a number: ";
    cin >> num;

    if (num % 2 == 0)
        cout << num << " is Even" << endl;
    else
        cout << num << " is Odd" << endl;

    return 0;
}

Even Odd Program in Java

import java.util.Scanner;

public class EvenOdd {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a number: ");
        int num = sc.nextInt();

        if (num % 2 == 0)
            System.out.println(num + " is Even");
        else
            System.out.println(num + " is Odd");

        sc.close();
    }
}

Conclusion

In this article, we learned how to check Even and Odd numbers using Python, C, C++, and Java.
This program is a foundation for beginners to practice conditionals and arithmetic operators.

The Even Odd program is one of the most basic problems in programming, but don’t underestimate it. This question is commonly asked in college exams like SRMU, BBD University, Integral University, and in placement coding rounds of many companies.

Why? Because it helps interviewers check whether a candidate understands:

  • Conditional statements
  • Basic input/output handling
  • Use of modulus operator (%)

If you’re preparing for placements or semester exams, learning such problems will definitely help.

👉 Next, try solving other beginner-level problems like Palindrome Number in Java or Armstrong Number in C.

For more examples and explanations, you can also check GeeksforGeeks Even Odd Program.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top