C Program to generate Decreasing Number Pyramid/Triangle

Leave a Comment
/* Sample Output
--------------------------------------------------------------------------------

1 1 1 1 1 1 1 1
2 2 2 2 2 2 2
3 3 3 3 3 3
4 4 4 4 4
5 5 5 5
6 6 6
7 7
8

0 1 2 3 4 5 6 7
1 2 3 4 5 6 7
2 3 4 5 6 7
3 4 5 6 7
4 5 6 7
5 6 7
6 7
7

2 3 4 5 6 7 8 9
4 5 6 7 8 9 10
6 7 8 9 10 11
8 9 10 11 12
10 11 12 13
12 13 14
14 15
16

--------------------------------------------------------------------------------
*/

#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,k,n;
clrscr();
for(i=1;i<10;i++)
{
printf("\n");
for(j=i;j<9;j++)
{
printf(" ");
printf("%d",i);
}
}
for(i=1;i<10;i++)
{
printf("\n");
for(j=i;j<9;j++)
{
printf(" ");
printf("%d",j-1);
}
}
for(i=1;i<10;i++)
{
printf("\n");
for(j=i;j<9;j++)
{
printf(" ");
printf("%d",j+i);
}
}
getche();
}

0 comments: