Thursday, October 16, 2014

Example for find the given value is odd or even in C++



Prog 20: write a program to find the given value is odd or even
#include<iostream.h>
#include<conio.h>
class number
{

int a;
public:
void getdata();
void display();
};


void number::display()
{
getdata();
if(a%2==0)
cout<<"\n no is even";

else
cout<<"\n No is odd";
}


void number::getdata()
{
cout<<"enter a";
cin>>a;
}
void main()
{
clrscr(); 
number n; 
n.display();
 getch();
}

Output:

enter a
7

No is odd

No comments: