Check number is even or odd

Write a program to check the given number is even or odd.

Even Number: A number that is divisible by 2.

Odd Number: A number that is not divisible by 2.

Example 1:

Input:12
Output:Even

  Example 2:

Input:7
Output:Odd

Approach:

Approach

Java

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

C++

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n=12;
    if(n%2==0)
       cout<<"Even\n";
    else
      cout<<"Odd\n";
   return 0;
}


No comments:

Post a Comment