Showing posts with label wap odd even using turnary operater. Show all posts
Showing posts with label wap odd even using turnary operater. Show all posts

Tuesday, 26 September 2017

Write a Program to Check Whether a Number is Even or Odd

C++ Program to Check Whether a Number is Even or Odd.


In this example,we used if...else statement to check given a number even or odd.

Even number. An even number which number is divided by 2 its called odd number.example 2,6,8,10


Odd number.An even number which number is not divided by 2 its called odd number.example 1,3,5,7,11

Example 1: Check Whether Number is Even or Odd using if or else

#include <iostream>
#include <conio.h>
using namespace std;
int main ()
    {
      int n;

   cout <<"plz enter number";
   cin>>n;

     if (n%2==0)
      cout << "Number is even";
        else
       cout <<"Number is odd";

       return 0;
       getch();
    }

      Output
_________________________
Number is even



Example 2: Check Whether Number is Even or Odd using ternary operators



include <iostream>
#include <conio.h>
using namespace std;
int main ()
    {
      int n;

   cout <<"plz enter number";
   cin>>n;

 (n%2==0)? cout <<"even":
  cout <<number is odd";

    return 0;
      getch ();
    }

output
---------------
Enter the number user
n= 7
number is odd





The people who want to learn programming. this website very beneficial for those peoples.