9.03.2011

19.Design numbers tringle pyramid

Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)

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

123454321
2345432
34543
454

5
***********************************/

4 comments:

  1. #include
    #include
    void main()
    {
    int i,j,total;
    clrscr();

    printf("enter the first value");
    scanf("%d",&i);
    printf("enter the second value");
    scanf("%d",&j);

    i+j=total;
    printf("addition is:");

    getch();
    }

    ReplyDelete
    Replies
    1. #include
      void main()
      {
      int i,j,total;
      clrscr();

      printf("enter the first value");
      scanf("%d",&i);
      printf("enter the second value");
      scanf("%d",&j);

      i+j=total;
      printf("addition is:%d",total);

      getch();
      }

      Delete