GoHacking.com: Ethical Hacking and Cyber Security
Home » C PROGRAMMING

C Program to Generate Numbers in Pyramid Pattern

Submitted by on Friday, 7 December 200710 Comments

This C program generates the numbers in pyramid pattern. It takes the input from two through nine and generates the numbers in the pyramid pattern. For example if the input is 4 then the program produces the following output

….1
1111112 2
111113 3 3
111.4 4 4 4 & so on..

CODE:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j,x=40,y=10;
clrscr();
printf(“Enter n (between 2 & 9)\n”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
gotoxy(x,y); /* To take the cursor to the co-ordinates x & y */
for(j=1;j<=i;j++)
{
printf(“%d “,i);
}
x=x-1;
y++;
}
getch();
}


By using/following this site you agree to our Legal Disclaimer

10 Comments »

  • Arindam said:

    Srikant, plz tell me how to connect access or sql as backend with c or c++ as frontend

  • hardik said:

    i want to c program logic

    it’s output will display like that:-

    *
    * *
    * *
    * *
    * *
    * * * * * *

    this type of output o want so plz help me…..

  • dipika said:

    hi!srikanth,how to generate the following:
    U
    U N
    U N I
    U N I X
    U N I X
    U N I
    U N
    U

  • sanjay khurana said:

    i want to print a pattern like
    *
    **
    ***
    ****
    in c++

    could neone help me please..

  • Sumon said:

    i want to print a pattern like
    1
    2 3
    3 4 5
    6 7 8 9 10

  • Sunpreet Singh said:

    hey can you send me the program for this output:
    using nested for loop
    A
    AB
    ABC
    ABCD

  • Dheeraj said:

    self explanatory program!

  • aceangelo said:

    pls, can u make a program that prints this:

    0
    01
    012
    0123
    01234
    0123
    012
    01
    0

  • nisarg said:

    #include
    #include
    void main()
    {
    char ch=’A'-1;
    int i,j,n=4;
    clrscr();
    for(i=1;i<=4;++i)
    {
    for(j=1;j<=i;++j)
    {
    printf("%c",ch+1);
    }
    printf("\n");
    }
    getch();
    }

  • manoj said:

    I want to print Pyramidal Program. Like this
    *
    * *
    * * *
    * * * * and so on.

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.