Even Odd Number

Definition & Explanation

  1. Odd Numbers:
    • An odd number is an integer that is not divisible by 2 without leaving a remainder.
    • In simpler terms, when an odd number is divided by 2, it does not result in an integer.
    • Odd numbers are always represented in the form 2n+1 or 2n−1, where n is an integer.
    • Examples of odd numbers include 1, 3, 5, 7, 9, and so on.
  1. Initialization: We start by initializing the variable n with the value 25.
  2. Condition Check (if statement): The program then checks whether n is divisible by 2 without leaving any remainder. This is done using the condition n % 2 == 0. If the condition is true (meaning n is divisible by 2 without remainder), the program executes the code inside the if block. Otherwise, it executes the code inside the else block.
  3. Output (printf, cout, or println): Depending on the programming language used (C, C++, or Java), the program outputs either “Even Number” or “Odd Number” based on the result of the condition check.
    • If n is divisible by 2 (i.e., it’s an even number), the program outputs “Even Number.”
    • If n is not divisible by 2 (i.e., it’s an odd number), the program outputs “Odd Number.”
  4. Termination: The program then exits or terminates after executing the appropriate output statement.

Even and Odd Number

  1. Even Numbers:
    • An even number is an integer that is divisible by 2 without leaving a remainder.
    • In other words, when an even number is divided by 2, the result is an integer.
    • Even numbers are always represented in the form 2n, where n is an integer.
    • Examples of even numbers include 2, 4, 6, 8, 10, and so on.
  2. Odd Numbers:
    • An odd number is an integer that is not divisible by 2 without leaving a remainder.
    • In simpler terms, when an odd number is divided by 2, it does not result in an integer.
    • Odd numbers are always represented in the form 2n+1 or 2n−1 where n is an integer.
    • Examples of odd numbers include 1, 3, 5, 7, 9, and so on.
C

Method 1 :

#include <stdio.h>

int main() {
    int n = 25;
    
    if (n % 2 == 0) {
        printf("Even Number\n");
    } else {
        printf("Odd Number\n");
    }
    
    return 0;
}

Output :

Odd Number
C++

Method 1 :

#include <iostream>

using namespace std;

int main() {
    int n = 25;
    
    if (n % 2 == 0) {
        cout << "Even Number" << endl;
    } else {
        cout << "Odd Number" << endl;
    }
    
    return 0;
}

Output :

Odd Number
JAVA

Method 1 :

public class Main {
    public static void main(String[] args) {
        int n = 25;
        
        if (n % 2 == 0) {
            System.out.println("Even Number");
        } else {
            System.out.println("Odd Number");
        }
    }
}

Output :

Odd Number
Python

Method 1 :

n=25
if n%2==0:
	print("even Number")
else:
	print("Odd Number")

Output :

Odd Number