Program to check whether the given number is even or odd

Problem statement:- Program to check whether the given number is even or odd.

Data requirement:-

   Input Data:-num

  Output Data:-String Output

Program in C

Here is the source code of the C Program to check whether the given number is even or odd.

Code:

#include<stdio.h>
int main()
{
    int num;
    printf("Enter a number:");
    scanf("%d",&num);

    if(num%2==0)
        printf("It is Even");
    else
        printf("It is Odd");
}

Input/Output:
Enter a number:55
It is Odd

Program in C++

Here is the source code of the C++ Program to check whether the given number is even or odd.

Code:

#include<iostream>
using namespace std;
int main()
{
    int num;
    cout<<"Enter a number:";
    cin>>num;

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

Input/Output:
Enter a number:74
It is Even

Program in Java

Here is the source code of the Java Program to check whether the given number is even or odd.

Code:

import java.util.Scanner;
public class oddoreven {

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

    if(num%2==0)
        System.out.println("It is Even");
    else
        System.out.println("It is Odd");
cs.close();
}
}

Input/Output:
Enter a number:
499
It is Odd

Program in Python

Here is the source code of the Python Program to check whether the given number is even or odd.

Code:

num=int(input("Enter a number:"))
if num%2 == 0:
     print("It is Even")
else:
    print("It is Odd")

Input/Output:
Enter a number:888
It is Even





Post a Comment

0 Comments