Write a C program to construct a pyramid of numbers. Home Notes Computer Programming Lab

#include 
#include
#include
void main()
{
int i, n, j, p = 40;
clrscr();
printf("enter the number of lines\n");
scanf("%d", &n);
printf("pyramid shape is\n");
for(i = 0; i <n ; i++)
{
gotoxy(p, i + 1);
for(j = 0 - i; j <= i; j++)
{
printf("%3d", abs(j % 2));
}
p = p - 3;
printf("\n");
}
getch();
}

Input & Output:

enter the number of lines
5
pyramid shape is
0
1 0 1
0 1 0 1 0
1 0 1 0 1 0 1

Leave a comment