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!!
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;
}
+ 2
This is entirely similar to the hourglass code you posted before. Just replace '*' with the current column.