Program to Check Whether a Number is Even or Odd

Description

To check a number is even or odd, divide the number by 2. If it gives remainder
0 then it is even and if it gives remainder 1 then it is odd.

C/C++

/* Java Program to Check Whether a Number is Even or Odd */
//Save it as CheckEvenOrOdd.java

#include<stdio.h>
int main(){

    int number;

    printf("Enter a number : ");
    scanf("%d",&number);

    if(number%2 == 0){
        printf("%d is even",number);
    }
    else{
        printf("%d is odd",number);
    }
    return 0;
}
Input:
Enter a number : 6

Output:
6 is even

Java

/* Java Program to Check Whether a Number is Even or Odd */
//Save it as CheckEvenOrOdd.java

import java.io.*;
import java.util.Scanner;
public class CheckEvenOrOdd {

    public static void main(String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        
        System.out.println("Enter a number : ");
        int number = scanner.nextInt();

        if(number%2 == 0){
            System.out.print(number+" is even");
        }
        else{
        	System.out.print(number+" is odd");
        }
    }
}
Input:
Enter a number : 
6

Output:
6 is even

Related Programs

1) Program to Check Whether a Number is Prime or Not
2) Program to Check Whether a Character is a Vowel or Not
3) Program To Check Armstrong Number
4) Check whether a given number is a perfect number or not
5) Program to Check Leap Year
6) Program to calculate Volume and Surface Area of Sphere
7) Program to add two complex numbers
8) Program to find HCF using Recursion
9) Program to calculate square root of a number without using standard library function sqrt()
10) Program to find HCF(Highest Common Factor)/GCD(Greatest Common Divisor) and LCM(Least Common Multiple)
Share Me

Leave a Reply