Answer to Question #280271 in C++ for Collay

Question #280271

2. Against All "Odds"

by CodeChum Admin


Looping numbers is fun, but it's even more exciting when we combine complex tasks to it, just like looping through a series of numbers and performing a series of code only to special numbers, like odd ones! And today, we're going to do just that.




Are you ready?






Instructions:


Input a random positive integer. This will serve as the starting point of the loop.

Using a while() loop, print out all the odd numbers starting from the inputted integer, until 0. The outputted numbers must all be separated by line.

Input


A line containing an integer.


10

Output


Multiple lines containing an integer.


9

7

5

3


1
Expert's answer
2021-12-16T04:45:32-0500
#include<iostream>

using namespace std;

int main()
{
	int value;
	do
	{
		cout<<"Please, input a random positive integer (0 - exit program): ";
		cin>>value;
		if(value<=0)break;
		int i=value;
		while(i>=0)
		{
			if(i%2==1)
			{
				cout<<i<<endl;
			}
			i--;
		}
	}while(true);
}

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