In this type of program we always find how many column present in a particular row. Because we know that we are always print in VDU horizontally. Here column number is same as (row number * 2 ) - 1 and the spaces are present at the right side of the character is equal to the (total no of row - current row). It is Pyramid which numbers are decrease in each row until the column number is equal to the row number.
#include <stdio.h> void main() { int r,c,n,s,p,fl=1; printf("Enter Total Number of row : "); scanf("%d",&n); for(r=1;r<=n;r++) { p=r; for(s=1;s<=n-r;s++) { printf(" "); } for(c=1;c<=2*r-1;c++) { printf("%d",p); if(c==r){fl=0;} ((fl==1)?(p--):(p++)); } fl=1; p=1; printf("\n"); } }
Enter Total Number of row : 6
1 212 32123 4321234 543212345 65432123456