Creating Triangle of Numbers in C
1
2 1
1 2 3 2 1
2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
2 1
1 2 3 2 1
2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
# include# include void main ( ) { clrscr ( ); int n,i,j,k; printf ("\n Enter no. of rows :"); scanf ("%d",&n); printf ("\n\n"); for (i =1;i < = n;i++) { for (j = 1;j < = n-i;j++) printf (" "); for (j = i;j > =1;j--) printf ("%d",j); for (j = 2;j < = i;j++) printf ("%d",j); printf ("\n"); } getch ( ); }
No comments:
Post a Comment