Computer Science, asked by mariapaulose2004, 4 months ago

write a c++ program to display first 20 even numbers

Answers

Answered by kandhunurivenkateshw
1

Explanation:

If you want to find out 20 even numbers consequently then

#include<iostream>

using namespace std;

int main()

{

int i,n;

cout<<"\n Enter the first number";

cin>>n;

cout<<"The even numbers are:";

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

{

if(i%2==0)

cout<<i<<" ";

}

}

If you want to obtain numbers randomly then

#include<iostream>

#include<cstdlib>

using namespace std;

int main()

{

int n,count=0;

cout<<"The even numbers are:";

while(count<=20)

{

n=rand();

if(n%2==0)

{

cout<<n<<" ";

count++;

}

}

}

Hope it helped!

Similar questions