Answer to Question #308836 in C++ for Chubby

Question #308836

Create a C++ program that allows 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-10T02:10:03-0500
using namespace std;


/*
	Create a C++ program that allows 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.
*/


#define MIN	20
#define MAX	40


int main()
{
	int a,n = MIN-1;
	while(n<MIN || n>MAX)	
	{
		cout<<"\n\tEnter a number from "<<MIN<<" to "<<MAX<<": "; cin>>n; 
 	}
	cout<<"\n\tEven Numbers are: ";
 	for(a=MIN;a<MAX+1;a++)
 	{
 		if(a%2==0) cout<<a<<", ";
	}
	cout<<"\n\tOdd Numbers are: ";
	a=MIN;
	do
	{
		if(a%2==1) cout<<a<<", ";
		a++;
	}while(a<MAX+1);
	return(0);
}

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