Program to Check Whether a Number is Even or Odd

Description

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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.
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.
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++

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/* 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;
}
/* 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; }
/* 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;
}
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Input:
Enter a number : 6
Output:
6 is even
Input: Enter a number : 6 Output: 6 is even
Input:
Enter a number : 6

Output:
6 is even

Java

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/* 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");
}
}
}
/* 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"); } } }
/* 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");
        }
    }
}
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Input:
Enter a number :
6
Output:
6 is even
Input: Enter a number : 6 Output: 6 is even
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