In: Computer Science
write a c++ program
. Ask the user to enter a number less than 100. Test the input to make sure it is correct, and use a while loop to continuously ask the user for correct input value if they don't follow the input rule. After receiving the correct input, test the number to see if it is even or odd. If it is odd, use a while loop to do the following: Output to the monitor all odd numbers from 1 to your input value. If the number is even, use a while loop to output to the monitor all the even numbers from 0 to your input value.
ANSWER:-
#include <iostream>
using namespace std;
int main() {
int n,i,j;
cout<<"enter a number less than 100 : ";
cin>>n;
while(n>=100)
{
cout<<"enter a valid number
less than 100 : ";
cin>>n;
}
if(n%2!=0)
{
i=1;
while(i<=n)
{
if(i%2!=0)
cout<<i<<" ";
i++;
}
}
if(n%2==0)
{
j=0;
while(j<=n)
{
if(j%2==0)
cout<<j<<" ";
j++;
}
}
return 0;
}
// OUTPUT:-
// If any doubt please comment