/* Program to Print the Following Output:
1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654321
*/
#include<stdio.h>
void main()
{
int i, j, k, space, n=9;
for (i=1; i<=n; i++)
{
for (j=1; j<=n-i; j++)
printf(" ");
for (j=1,k=2*i-1; j<=2*i-1; j++,k--)
{
if (j <= k)
printf("%d", j);
else
printf("%d", k);
}
printf("\n");
}
}
// Second Method.
int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=5;j>i;j--)
printf(" ");
for(j=1;j<=i;j++)
printf("%d ",j);
for(j=j-2;j>=1;j--)
printf("%d ",j);
printf("\n");
}
return 0;
}
#include<stdio.h>
void main()
{
int i, j, k, space, n=9;
for (i=1; i<=n; i++)
{
for (j=1; j<=n-i; j++)
printf(" ");
for (j=1,k=2*i-1; j<=2*i-1; j++,k--)
{
if (j <= k)
printf("%d", j);
else
printf("%d", k);
}
printf("\n");
}
}
// Second Method.
int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=5;j>i;j--)
printf(" ");
for(j=1;j<=i;j++)
printf("%d ",j);
for(j=j-2;j>=1;j--)
printf("%d ",j);
printf("\n");
}
return 0;
}