Print even numbers in c++ || using class


Print even numbers in c++:
Even numbers are the numbers which are divisible by 2 that type number is known as Even number
Remember this 2 point

for(i=0;i<n;i++)

if(i%2==0)

Program:
#include<iostream>

using namespace std;

class even

{

int n, i;

public:

void read();

void print();

};
void even::read()

{

cout<< "enter the number you want to print even number";

cin>>n;

cout<<"even number of size"<<n<<"is\n";

}

void even::print()

{

for(i=0;i<n;i++)

if(i%2==0)

cout<<i<<"\n";

}
int main()

{

even ob1;

ob1.read();

ob1.print();

}

Output:

Click  Here Executable "CPP" file:


Recommended Posts:

Post a Comment

2 Comments