Answer to Question #309127 in C++ for Chubby

Question #309127

Create a C++ program that allows the user to enter a maximum number from 20-40. From the number entered by the user, print the even numbers using for loop and do while loop for the odd numbers.


1
Expert's answer
2022-03-12T04:55:41-0500

Here is program:

int main()
{
	int r = 0;
	const int size = 5;
	int arr[size]{};
	cout << "Enter elements array from 20-40.: " << endl;
	for (int i= 0; i < size; i++)
	{
		cin >> arr[i];
		if (arr[i] < 20 || arr[i] > 40)
		{
			cout << "Error!" << endl;
			break;
		}
	}
	for (int j = 0 ; j < size; j++)
	{
		if (arr[j] % 2 == 0)
		{
			cout << "Even numbers: " << arr[j] << endl;
		}
	}
	while (r < size)
	{
		if (arr[r] % 2 != 0)
		{
			cout << "ODD numbers: " << arr[r] << endl;
		}
		r++;
	}
}

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