- To print full triangle pattern using number
User Input: 3
Output:
1 1 2 1 1 2 3 2 1
#include <iostream>
using namespace std;
int main() {
int rows,k;
cout <<"Enter number of rows: ";
cin >> rows;
for(int i=rows; i>=1; i--) {
k=1;
for(int j=1; j<=(2*rows-i); j++) {
if(j<i)cout<<" ";
else {
if(j<rows)cout<<k++<<" ";
else cout<<k--<<" ";
}
}
cout<<endl;
}
return 0;
}
Enter number of rows: 4 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1Program
Main Logic :
for(int i=rows; i>=1; i--) {
k=1;
for(int j=1; j<=(2*rows-i); j++) {
if(j<i)cout<<" ";
else {
if(j<rows)cout<<k++<<" ";
else cout<<k--<<" ";
}
}
cout<<endl;
}
Concept
Coming Soon !
QuickThe dreams I chased took me on a journey, a journey more rewarding than the goals