Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in c++ Write a program that reads a positive odd whole number n and prints a pyr

ID: 3673639 • Letter: I

Question

in c++ Write a program that reads a positive odd whole number n and prints a pyramid where the first row contains all numbers from 1 to n (i.e., ascending order), the second row displays all numbers from 2 to n – 1, the third row displays all numbers from 3 to n – 2, etc. The last row will contain only a single value, i.e. the middle value in the range, i.e. 1 to n. Each successive row contains two fewer values than the previous row, i.e the two values at the ends of the previos rows are missing.

Explanation / Answer

#include <iostream>
using namespace std;
int main()
{
int n,m;
cout << "Enter a positive odd number: ";
cin >> n;
for(int i=1;i<=((n+1)/2);i++)
{
for (int j=1; j<=i-1; j++)
{
cout << " ";
}
for (int k=n-i+1;k>=i;k--)
{
m=k%10;
cout << m;
}
cout << endl;
}
return 0;
}