C++ Program to print first n odd numbers in descending order
In this program, You will learn how to print first n odd numbers in descending order in C++.
5th => 9 7 5 3 1
Example: How to print first n odd numbers in descending order in C++.
#include<iostream>
using namespace std;
int main() {
int n, i, a;
cout << "Enter a number:";
cin>>n;
cout << "List is :";
for (i = n - 1; i >= 0; i--) {
a = 1 + i * 2;
cout << a << " ";
}
return 0;
}
Output:
Enter a number:5
List is :9 7 5 3 1