Answer to Question #309126 in C++ for Chubby

Question #309126

Create a C++ program using for loops and do while loop that give this output:



Enter the maximum number are: 21


Even numbers are :2 4 6 8 10 12 14 16 18 20

Odd numbers are :1 3 5 7 9 11 13 15 17 19 21


1
Expert's answer
2022-03-13T06:03:16-0400
#include <iostream>

using namespace std;

int main()
{
	int value;
	cout << "Please, enter a value: ";
	cin >> value;
	cout << "Even numbers are: ";
	for (int i = 2; i <= value; i++)
	{
		if (i % 2 == 0)
			cout << i << " ";
	}
	cout << "\nOdd numbers are: ";
	int i=1;
	do
	{
		if(i%2==1)
			cout << i << " ";
		i++;
	} while (i<=value);
}

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