Skip to main content

Write a C C++ program to check whether given number is even or odd


Flowchart
Draw a flowchart to check entered number is even or odd


Coding in C

#include<stdio.h>
int main()
{
    int n;
    printf("Enter a number: ");
    scanf("%d",&n);
    if(n%2==0)
    {
        printf("Even number");
    }
    else
    {
        printf("Odd number");
    }
    return 0;
}

Coding in C++

#include<iostream>
using namespace std;
int main()
{
    int n;
    cout<<"Enter a number: ";
    cin>>n;
    if(n%2==0)
    {
        cout<<"Even number";
    }
    else
    {
        cout<<"Odd number";
    }
    return 0;
}

Output


Check whether given number is even or odd output