0

Inverted Pyramid

Hello!! I wrote this program: https://code.sololearn.com/cjjsBxubH61x/?ref=app I was wondering how I could modify it to get the following output: (If n=7) 1234567 23456 345 4 (If n=9) 123456789 2345678 34567 456 5 Thanks for the help!!

9th Oct 2018, 4:21 AM
Miqaela Weller
Miqaela Weller - avatar
2 Answers
+ 11
#include <iostream> using namespace std; int main() { int n; cout << "Enter odd, positive n"; cin >> n; cout << endl; for(int i = 0; i < n; i++) { for(int spaces = 0; spaces < i; spaces++) cout << " "; for(int j = i + 1; j <= (n - i); j++) { cout << j; } cout << endl; } return 0; }
9th Oct 2018, 8:55 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
This is entirely similar to the hourglass code you posted before. Just replace '*' with the current column.
9th Oct 2018, 6:38 AM
HoĂ ng Nguyễn Văn
HoĂ ng Nguyễn Văn - avatar