Can any one help me to optimize this code. Or possible to alter and make it more simple

The out put i need to get is

```
1
212
32123
.......
```

this is the code

```
main()
{
int i,j,k,n=4,val,flag=0;
for(i=0;i<n;i++)
{
for(j=1;j<n-i;j++)
putchar(' ');
val=i+1;
flag=0;
for(k=0;k<2*i+1;k++)
{
printf("%d",val);
if(val == 1)
flag = 1;
if(flag)
val++;
else
val--;
}
putchar('\n');
}
getch();
}
```

Thanks