Write a C program to construct a pyramid of numbers.

Algorithm:

Step 1: Start
Step 2: Read n value as integer
Step 3: for p:1 to n increment p by 1
        begin
            for q:1 to n increment q by 1
               m = p;
            for q:1 to p increment q by 1
               print m++
                m = m - 2;
            for q:1 to p increment q by 1
                print m--
         end
Step 4: Stop

Program:

#include <stdio.h>
#include <conio.h>
#include <math.h>
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