Code: Triangle of Numbers
- Get link
- X
- Other Apps
Code: Triangle of Numbers
Send Feedback
Print the following pattern for the given number of rows.
Pattern for N = 4
The dots represent spaces.
Input format :
Integer N (Total no. of rows)
Output format :
Pattern in N lines
Constraints :
0 <= N <= 50
Sample Input 1:
5
Sample Output 1:
1
232
34543
4567654
567898765
Sample Input 2:
4
Sample Output 2:
1
232
34543
4567654
#include <iostream>using namespace std;
int main() { /* Read input as specified in the question. * Print output as specified in the question. */// int n;// int row=1;// cin>>n;// while(row>=n){// int space=1;// while(n-row>=space){// cout<<" ";// space++;// } // int j=1;// while(row>=j){// cout<<j;// j++;// } // int k=row-1;// while(k>=1){// cout<<k;// k--;// }// cout<<endl;// row++;// } // int n;// int row=1;// cin>>n;// while(n>=row){// int space=1;// while(n-row>=space){// cout<<" ";// space++;// } // int j=1;// while(row>=j){// cout<<j;// j++;// } // int k=row-1;// while(k>=1){// cout<<k;// k--;// }// cout<<endl;// row++;// } // int n; int row=1; cin>>n; while(n>=row){ int space=1; while(n-row>=space){ cout<<" "; space++; } int copy=row; int j=1; while(row>=j){ cout<<copy; copy++; j++; } int dec=row-1; int k=(2*row-2); while(dec>=1){ cout<<k; k--; dec--; } cout<<endl; row++; } }
- Get link
- X
- Other Apps
Comments
Post a Comment