#include <iostream>
using namespace std;
/*
MyLearnings:-
1. I lacked visualization for spacing, and should've started from backward to forward which is correct way to do this code
*/
int main() {
int n = 5;
// outer loop
for(int i = 1; i <= n; i++){
// inner loop
for(int space = 1; space <= n-i; space++){
cout << " ";
}
// nums backward
for(int j = i; j >= 1; j--){
cout << j;
}
// nums forward
for(int j = 2; j <= i; j++){
cout << j;
}
cout << endl;
}
return 0;
}
OUTPUT-
1
212
32123
4321234
543212345
No comments:
Post a Comment