Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to print pyramid of numbers as shown in description

Posted By: Cesar Gonzalez     Category: C Programming     Views: 22441

WRITE A PROGRAM TO GENERATE FOLLOWING FIGURE OF N LINES.
INPUT N FROM KEYBOARD.

______0
____1 0 1
__2 1 0 1 2
3 2 1 0 1 2 3

consider space in place of line.

Code for Program to print pyramid of numbers as shown in description in C Programming

#include<stdio.h>
#include<conio.h>
void main()
{
        int i,n,j;
        clrscr();
        printf("\n Please Give The Value of N:  ");
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
            for(j=0;j<n-i;j++)
            printf("  ");
            for(j=i;j>=0;j--)
            printf(" %d",j);
            for(j=1;j<=i;j++)
            printf(" %d",j);
            printf("\n");
        }
        getch();
}


********************* OUTPUT ***************************************

     Please Give The Value of N:  9


                       0
                     1 0 1
                   2 1 0 1 2
                 3 2 1 0 1 2 3
               4 3 2 1 0 1 2 3 4
             5 4 3 2 1 0 1 2 3 4 5
           6 5 4 3 2 1 0 1 2 3 4 5 6
         7 6 5 4 3 2 1 0 1 2 3 4 5 6 7
       8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8


**********************************************************************
  
Share: 



Cesar Gonzalez
Cesar Gonzalez author of Program to print pyramid of numbers as shown in description is from Philadelphia, United States.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Sri Ragavi from France Comment on: Mar 09
hello sir

i want to know how we can use while loop.

which out put must be-
1
12
123
1234
12345

please help me

View All Comments