C Program to Print 1-212-32123 Triangle (Pyramid) Pattern
In this program, we generate pyramid like triangle pattern using numbers. And numbers have pattern like this: 1 in first line, 212 in second line, 32123 in third line and so on.
Numeric Pyramid Pattern C Program
#include<stdio.h>
int main()
{
int i,j,row;
printf("Enter number of rows: ");
scanf("%d",&row);
for(i=1;i<=row;i++)
{
for(j=1;j<=row-i;j++)
{
printf(" ");
}
for(j=i;j>=1;j--)
{
printf("%d", j);
}
for(j=2;j<=i;j++)
{
printf("%d", j);
}
printf("\n");
}
return 0;
}
Output of above program
Enter number of rows: 8 1 212 32123 4321234 543212345 65432123456 7654321234567 876543212345678
Another Method
#include<stdio.h>
#include<math.h>
int main()
{
int i,j,row;
printf("Enter number of rows: ");
scanf("%d",&row);
for(i=1;i<=row;i++)
{
for(j=1;j<=row-i;j++)
{
printf(" ");
}
for(j=-i;j<=i;j++)
{
if(j==0||j==1)
{
continue;
}
printf("%d", abs(j));
}
printf("\n");
}
return 0;
}
Output of above program
Enter number of rows: 6 1 212 32123 4321234 543212345 65432123456