C++ program to find even or odd number.

Q23. Write a program to find whether a given number is even or odd.

Ans.

#include<iostream.h>

#include<conio.h>  //for clrscr()

 

//Main function

void main()

{

int n;

clrscr();  //for clear screen

cout<<“\n Enter a number: “;

cin>>n;

if(n%2==0)

{

cout<<“\n The given number is even.”;

}

else

{

cout<<“\n The given number is odd.”;

}

 

getch();  //To hold the output screen

}

//End of main()

 

Output 1:

Enter a number: 6

The given number is even.

 

Output2:

Enter a number: 5

The given number is odd.

Leave a Reply

Your email address will not be published. Required fields are marked *