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
#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);
}
Comments
Leave a comment