Answer to Question #217934 in C++ for Rosie

Question #217934
Question 4: write a program uses for loop to print numbers 1 to 20

Question 5: write a program uses for loop that print only the even numbers between 1 and 20, that is, 2 4 6 8 10 12 14 16 18 20
1
Expert's answer
2021-07-17T01:35:39-0400
//Question 4
#include <iostream>
using namespace std;
int main()
{
	//Question 4
	//use for loop print 1 ..20
	cout << "================use for loop print [1..20]=====================\n";
	cout << "\t\t";
	for (int i = 1; i <=20; i++)
		cout << i << " ";
	cout << "\n===============================================================\n";
	return 0;
}
//Question 5
#include <iostream>
using namespace std;
int main()
{
	//Question 4
	//use for loop print even number 1 ..20 [2,4,6.....20]
	cout << "================use for loop print [1..20]=====================\n";
	cout << "\t\t";
	for (int i = 2; i <=20; i+=2)
		cout << i << " ";
	cout << "\n===============================================================\n";
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS