/* ###1### in this case input is 4 when i=0 u have 3 spaces

** ##2#2## when i=1 u have 2 spaces

** #3###3# when i=2 u have 1 space

** 4#####4 when i=3 u have 0 space

*/

#include<stdio.h>

main()

{

int i, j, numspace, input;

printf(" Type a number ");

scanf("%d", &input);

i = 0;

while(i < input)

{

numspace = input - ( i + 1); // in the first line when input is 4 and i is 0

// u have 4 - (1 + 0 ) spaces

// now a loop for printing spaces

for( j = 0; j< numspace; j++)

printf(" "); // this prints spaces

// now to print the number... after printing the spaces u simply print the number

// whis is ( i + 1 ) since on the first line.. the number is 1 and i is 0

// on the 2nd line where i is one.. the number is 2 .. that is ( i + 1 ) and so on

// so we have the following

printf("%d", (i + 1) );

// now.. to print the other number on the line...

// note that on the second line u have this sequence 2#2 one space btween them where i = 1

// and on the 3rd line............................. 3###3 3spaces between them where i = 2

// soo.. we have 2*i -1 spaces beween the number

// for i = 1 ... 2*1 - 1 = 1 for i = 2.... 2*2 - 1 = 3

// so.. we loop again for the other spaces

// but first we define the number of spaces

if(i>0) // since on the first line u only have one number

{

numspace = 2*i -1;

for(j=0; j<numspace; j++)

printf(" ");

printf("%d", i+1);

}

// almost done.. now we have to print a newline and increment i

printf("\n");

i++;

}

}