#include<iostream>

using namespace std;

class even{

public:

int i=1,count;

void printEven(int n)

{

cout<<"The first "<<n<<" even numbers are "<<endl;

for(count=0;count<n;)

{

if(i%2==0)

{

cout<<i<<"\t";

count++;

}

i++;

}

}

};

int main()

{

even obj1;

int n;

cout<<"Please enter how many even numbers you want."<<endl;

cin>>n;

obj1.printEven(n);

cout<<endl;

return 0;

}

Output 1:

Please enter how many even numbers you want.

5

the first 5 even numbers are

2 4 6 8 10

Output 2:

Please enter how many even numbers you want.

1

the first 5 even numbers are

2

Output 3:

Please enter how many even numbers you want.

10

the first 5 even numbers are

2 4 6 8 10 12 14 16 18 20

using namespace std;

class even{

public:

int i=1,count;

void printEven(int n)

{

cout<<"The first "<<n<<" even numbers are "<<endl;

for(count=0;count<n;)

{

if(i%2==0)

{

cout<<i<<"\t";

count++;

}

i++;

}

}

};

int main()

{

even obj1;

int n;

cout<<"Please enter how many even numbers you want."<<endl;

cin>>n;

obj1.printEven(n);

cout<<endl;

return 0;

}

Output 1:

Please enter how many even numbers you want.

5

the first 5 even numbers are

2 4 6 8 10

Output 2:

Please enter how many even numbers you want.

1

the first 5 even numbers are

2

Output 3:

Please enter how many even numbers you want.

10

the first 5 even numbers are

2 4 6 8 10 12 14 16 18 20

## No comments:

## Post a Comment