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