9.01.2011

5.Design triangle pyramid

Q. Write a program to generate a following @'s triangle?
                                       




@



@ @


@ @ @

@ @ @ @
@ @ @ @ @
Ans.
/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r,c,sp;
 printf("Enter loop repeat number(rows): "); 
 scanf("%d",&num);
 for(r=1; num>=r; r++)
 {
  for(sp=num-r; sp>=1; sp--)
     printf(" ");
  for(c=1; c<=r; c++)
     printf("@");
  printf("\n");
 }
 getch();
 return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5





@



@@


@@@

@@@@
@@@@@

***********************************/

17 comments:

  1. sir can u please tell me in details what is the work of "sp--"..

    ReplyDelete
    Replies
    1. Sp-- tell us about the decrease of space in the pattern like
      ssssss@
      sssss@@
      ssss@@@
      sss@@@@
      ss@@@@@
      s@@@@@@
      Here 's' indicates the decreasing order of space in pattern. Just like sp

      Delete
  2. This is wrong plz tell correct solution

    ReplyDelete
    Replies
    1. Anish Pls run it once!!! Program is absolutely correct..

      Delete
  3. thanku for uploading the code

    ReplyDelete
  4. tell me the c program for following structure:
    1 1
    12 21
    123 321
    1234 4321
    123454321

    ReplyDelete
    Replies
    1. #include

      int main(void) {
      int rows,i,k;
      int ary[10];
      scanf("%d",&rows);

      for(i=1;i<=rows;i++)
      {
      for(k=1;k<=i;k++)
      {
      ary[k]=k;
      printf("%d",k);
      }
      printf(" ");
      for(k=(k-1);k>=1;k--)
      {
      printf("%d",ary[k]);
      }
      printf("\n");
      }

      return 0;
      }

      Delete
  5. =1; $space--)

    printf("&nbsp&nbsp&nbsp&nbsp");
    for($c=0; $c<=$r; $c++)

    echo "@";
    echo"
    ";
    }



    ?>

    ReplyDelete
  6. import java.util.*;
    class Pattern5
    {
    public static void main(String[] args)
    {
    System.out.println("Enter the number of rows:");
    Scanner sc=new Scanner(System.in);
    int num=sc.nextInt(); //Number of rows taking from keyboard

    for(int row=1;row<=num;row++) // NUmber of rows
    {
    for(int space=num;space>row;space--)
    {
    System.out.print(" ");
    }

    for(int col=1;col<=row;col++) //column stars printing
    {
    System.out.print("#");
    }
    System.out.println();

    }
    }
    }

    ReplyDelete
  7. There is no basic difference between the following programs. But when I run these two they show difference shaped pyramids. Can anybody tell me why?
    ................................................................................................
    Programe of Q. NO-5 of this blog:

    #include
    #include
    void main()
    {
    clrscr();
    int num=5,r,c,sp;
    for(r=1;r<=num;r++)
    {
    for(sp=num-r;sp>=1;sp--)
    {
    printf(" ");
    }
    for(c=1;c<=r;c++)
    {
    printf("*");
    }
    printf("\n");
    }
    getch();
    }
    ........
    my programe:

    #include
    #include
    void main()
    {
    clrscr();
    int row, space, star;
    for(row = 1; row<=5; row++)
    {
    for(space = 5-row; space >=0; space--)
    {
    printf(" ");
    }
    for(star = 1; star<=row; star++)
    {
    printf(" * ");
    }
    printf("\n");
    }
    getch();
    }

    ReplyDelete
  8. #include
    main()
    {
    int i,j,k,n;
    printf("Enter the number of rows");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    for(k=n;k>i;k--)
    {
    printf(" ");
    }
    for(j=1;j<=i;j++)
    {
    printf("@");
    }
    printf("\n");
    }
    }

    ReplyDelete
  9. 12,
    12,13,
    13,14,12,
    15,12,13,14,
    13,14,15,16,12,
    16,17,12,13,14,15,
    13,14,15,16,17,18,12,
    17,18,19,12,13,14,15,16,
    13,14,15,16,17,18,19,20,12,
    18,19,20,21,12,13,14,15,16,17,
    13,14,15,16,17,18,19,20,21,22,12,


    how i get this number triangle?? in easy way!! please help me

    ReplyDelete
  10. please tell me the solution of

    &
    &
    & &
    & & &

    ReplyDelete
    Replies
    1. #Anil Saini

      Your required symbol triangle pattern C program source code solution as:

      http://cprogrammingcodes.blogspot.com/2011/09/4design-tringle-praymid.html

      Delete