adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Check given number is even or odd in C++ program

Check given number is even or odd using if else statement

#include<iostream>
#include<conio.h>
  using namespace std;
   int main()
    {
       int n; //Declaration of variable
       cout<<"Enter a number:-";
       cin>>n;
       if(n%2==0) 
         cout<<n<<" is even no.";
       else
         cout<<n<<" is odd no.";
       getch();
    }


Check given number is even or odd using Conditional operator


#include<iostream>
#include<conio.h>
  using namespace std;
   int main()
    {
       int n; //Declaration of variable
       cout<<"Enter a number:-";
       cin>>n;
       n%2==0?cout<<n<<" is even no.":cout<<n<<" is odd no.";
       getch();
    }

Check given number is even or odd using Switch case statement

#include<iostream>
#include<conio.h>
  using namespace std;
   int main()
    {
       int n; //Declaration of variable
       cout<<"Enter a number:-";
       cin>>n;
       switch(n%2)
          {
           case 0:cout<<n<<" is even no.";
             break;
           case 1:cout<<n<<" is odd no.";
     break;  
   }
       getch();
    }

Output:-







 Related programs in C++

Post a Comment

0 Comments