write a c++ program to display first 20 even numbers
Answers
Answered by
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
Math,
2 months ago
Business Studies,
2 months ago
Math,
2 months ago
Social Sciences,
4 months ago
India Languages,
4 months ago
History,
10 months ago
Computer Science,
10 months ago
Biology,
10 months ago