Answer to Question #287112 in C for jay

Question #287112

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:

  1. Input a positive integer. This will serve as the starting point of the loop.
  2. 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.
  3. Also remember that since the loop goes to descending order, a decrement variable shall be created and decreased per iteration for the loop to terminate when it reaches 0.

Input


1. An integer

Output


The first line will contain a message prompt to input the integer.

The succeeding lines contain the odd numbers.

Enter n: 10
9
7
5
3
1
1
Expert's answer
2022-01-13T12:32:33-0500
#include <iostream>


int main(int argc, char* argv[])
{
    int X;
    std::cout << "Enter X: ";
    std::cin >> X;
    X--;
    while (X > 0)
    {
        if (X % 2 == 1)
        {
            std::cout << X << std::endl;
        }
        X--;
    }




    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
APPROVED BY CLIENTS