Write a program that asks the user to enter an odd number and prints out a triangle pattern. For example, if the user enters 5, the output is
note: There is one space between the numbers in each line
1 3 5
1 3
1
If the user enters 9 the output is:
1 3 5 7 9
1 3 5 7
1 3 5
1 3
1
program language: C++
#include <iostream> using namespace std; int main() { int n; cout<<"Enter a odd number: "; cin>>n; for(int j = n;j>=1;j-=2){ for(int i = 1;i<=j;i+=2){ cout<<i<<" "; } cout<<endl; } return 0; }
Get Answers For Free
Most questions answered within 1 hours.