Please use C++ Language : which contains 3 for-loops Write a program pyramid. cp
ID: 3564588 • Letter: P
Question
Please use C++ Language : which contains 3 for-loops
Write a program pyramid. cpp that reads a positive odd whole number n and prints a pyramid where the first row contains all numbers from n down to 1 (i.e., descending order), the second row displays all numbers from n - 1 down to 2, the third row displays all numbers from n - 2 down to 3, etc. The last row will contain only a single value, i.e. the middle value in the range, i.e. n down to 1. Each successive row contains two fewer values than the previous row, i.e. the two values at the ends of the previous row are missing. For example, if n is 9, then the program will output: If n is 13, then the program will output: The ith row contains n - (2i - 2) values. Each column displays the same number. If a row has more than 10 digits, the digit after 0 should start again from 9.Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"Please Enter the number n : ";
cin>>n;
cout<<n<<endl;
int i,j,k;
for(i=0;i<=n/2;i++){
for(k=0;k<i;k++) cout<<" ";
for(j=n-i;j>i;j--){
cout<<j%10;
}
cout<<endl;
}
return 0;
}
//Sample outputs
Executing the program....
$demo