Exforsys
+ Reply to Thread
Results 1 to 6 of 6

how to write a pyramid program?

This is a discussion on how to write a pyramid program? within the C and C++ forums, part of the Programming Talk category; How 2 write a pgrm 4 the output below 1 2 3 4 5 6 7 8 9 10 thanks ...

  1. #1
    srknth_chin2 is offline Junior Member Array
    Join Date
    Jun 2007
    Answers
    4

    how to write a pyramid program?

    How 2 write a pgrm 4 the output below
    1
    2 3
    4 5 6
    7 8 9 10

    thanks in advance


  2. #2
    rasmiranjanbabu is offline Junior Member Array
    Join Date
    Oct 2009
    Location
    Bangalore, India
    Answers
    2

    Dummy Solution

    Try to optimize the code

    #include<stdio.h>
    void main()
    {
    int i,j,k = 5, l=1;

    for(i = 0; i <=3 ; i++)
    {
    for(j = 0; j <=10 ; j++)
    {
    if ((i == 0) && (j == 0))
    {
    printf("%d", l);
    l++;
    break;
    }
    if (i != j)
    {
    printf("%d ", l);
    l++;
    }
    if(i == j)
    {

    printf("%d ", l);
    l++;
    break;

    }


    }
    printf("\n");
    }
    }


  3. #3
    moonlight is offline Banned Array
    Join Date
    Jul 2008
    Answers
    27
    Hey, try it out

    public void run() {
    int base = 14;
    for (int i = 0; i < base; i++)
    {
    for (int j = 1; j < BRICK_HEIGHT; j++)
    {
    int x = BRICK_WIDTH * i;
    int y = getHeight() - (BRICK_HEIGHT * j);
    GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
    add(brick);
    }
    }
    }


  4. #4
    Mr.CheCco is offline Junior Member Array
    Join Date
    Jan 2010
    Answers
    1
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    int i,j,k;
    printf("enter the no of row --");
    scanf("%d",&i);

    for(j=0;j<=i-1;j++)
    {
    for(k=0;k<=j;k++)
    {
    printf("*");
    }
    printf("\n");
    }

    getch();
    }

    O/P
    enter the no of row --5
    *
    **
    ***
    ****
    *****


    try this out


  5. #5
    saibaba070 is offline Junior Member Array
    Join Date
    Aug 2010
    Answers
    1
    int main()
    {
    int n ,i,j,t=0;
    ///////// read n
    for(i=0;i<n;i++)
    {

    for(j=0;j<i;j++)
    {
    printf("%d",t);
    t++;
    }
    }
    }


  6. #6
    rahulguptalnct is offline Junior Member Array
    Join Date
    Sep 2010
    Answers
    2
    #include<stdio.h>
    #include<conio.h>

    void main()
    { clrscr();
    int i,j,n=1;

    for(i=1;i<=4;i++){
    for(j=1;j<=i;j++){

    printf("%d",n);
    n++;
    printf("");
    }

    printf("\n");

    }


    getch();


    }

    Last edited by admin; 09-23-2010 at 09:30 AM.

    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...