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.
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++;
	}
}
Comments