Write a C C++ program to check odd or even number

Write a C C++ program to check odd or even number

C-Language के विभिन्न Control Statements या Programming Constructs को जानने के लिए देखें—Control statements in C

If statement और इसके विभिन्न प्रकारो को जानने के लिए देखें—If statements in C

Flowchart to check odd or even number

Checking whether given number is even or odd flowchart

C program to check odd or even number

#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;
}

C++ program to check odd or even number

#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 of C C++ program to check odd or even number

Enter a number: 5
Odd number
Enter a number: 72
Even number

Other decision making programs in C C++

  1. Absolute value of number (simple if)
  2. Checking leap year (if else)
  3. Greater in two numbers (if else)
  4. Finding grade from percent (else if ladder)
  5. Total percent and division (else if ladder)
  6. Greatest in three numbers (nested if)
  7. Simple calculator program (switch case single case)
  8. Switch between Mon to Sun (switch case single case)
  9. Checking vowel or consonant (switch case multiple case)
  10. Number of days in a month (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer