# How to print this?

closed Sep 20
5

4  5

3  4  5

2  3  4  5

1  2  3  4  5

answered Sep 4 by (78,090 points)

To solve this problem you could use nested loops: a loop inside a loop would do the trick for you.

The outer loop would go through the rows one by one, we could call the loop variable row.

The inner loop would go from N - row until it reaches N (N = 5 in your example) and print each number.

After the inner loop terminates, you can print a line break so the next iteration of the outer loop would start printing numbers in a new line.

Allow me to write some pseudo-code for you:

```function: PrintNumberPyramid
arg: numRows

for row: [0, numRows)
for digit: [numRows - row, numRows]
print digit
print '\n'```

Note: [a, b] denotes a range with both left and right boundaries included while [a, b) denotes a range where the left boundary is included but the right boundary is excluded.

This should give you enough ideas to start coding. Share your solution when finished!

Good luck!

answered Sep 8 by (300 points)
#include <iostream>
using namespace std;
int main() {
int n,i,j;
cin>>n;
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
cout<<n-i+j;
}
cout<<endl;
}

return 0;
}
answered Sep 8 by (190 points)
#include <stdio.h>

int main()
{
int n;scanf("%d",&n);
for(int i=0;i<n;i++,printf("\n"))for(int j=n;j>=n-i;j--)printf("%d ",j);
return 0;
}
+1 vote
answered Sep 8 by (160 points)
#include<stdio.h>
int main()
{
int i,j,n;

printf("Enter how many rows you want : ");
scanf("%d",&n);

for(i=n;i>0;i--)
{
for(j=i;j<=n;j++)
printf(" %d",j);

printf("\n");
}

return 0;
}
+1 vote
answered Sep 16 by (560 points)
#include<stdio.h>

void main(){

int i,j,a;

scanf("%d",&a);

for(i=1;i<=a;i++){

for(j=a;j>=a-i;j--){

printf("%d ",j);

}

printf("\n");

}

}