#include <stdio.h>
int main()
{
int i, space, rows, k=0, count = 0, count1 = 0;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=1; i<=rows; ++i)
{
//print space until sapce value is not equal/less than (sapce-i), where
// i is current row Number
for(space=1; space <= rows-i; ++space)
{
printf(" ");
++count; //increment count after each space
}
//after printing all spaces, let's start number printing loop
// here while loop is used and it will print unless
//k is not euqal to 2*CurrentRow-1
while(k != 2*i-1)
{
//Now, looking at pattern formula is to print I(CurrentRow)+ Current K
// if Count is less than TotalRow -1
if (count <= rows-1)
{
printf("%d ", i+k);
++count;
}
else
{
++count1;
printf("%d ", (i+k-2*count1));
}
++k;
}
//reset all values to 0,except CurrentRow value and total row value
count1 = count = k = 0;
printf("\n");
}
return 0;
}