9.02.2012

Number pyramid

Q. Write a C program to print the following number pyramid.
or
Q. write a C program to print the following number triangle.

123456654321
1234554321
12344321
123321
1221
11

Ans.

/*c program for print the number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
  int num,i,j,n,r;
  printf("Enter number of rows: ");
  scanf("%d", &num);
  n = num;
  printf("\n");
  for(r=1; r<=num; r++,n--)
  {
     for(i=1; i<=n; i++)
         printf("%d",i);
     for(j=n; j>=1; j--)
         printf("%d",j);
     printf("\n");
  }
  getch();
  return 0;
}

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

The output of above program would be:
*****************************************************/

Output of number pyramid C program
Figure: Screen shot for number pyramid C program


Related Programs:

Q. Write a C program to print the following character pyramid.

       ABCDEFFEDCBA
       ABCDEEDCBA
       ABCDDCBA
       ABCCBA
       ABBA
       AA

You might also like:

  1. Big 98+ C pyramid programs list
  2. Latest user asking pyramid programs list



5 comments:

  1. #include
    int main()
    {
    int i,j,r,n;
    printf("Enter the no. of rows: ");
    scanf("%d",&n);
    printf("The required triangle is:\n\n");
    for(r=0;r0;r++,n--)
    {
    for(i=0;i0;j--)
    printf("%c",j+64);
    printf("\n");
    }
    return 0;
    }

    ReplyDelete
  2. #include
    int main()
    {
    int i,j,r,n;
    printf("Enter the no. of rows: ");
    scanf("%d",&n);
    printf("The required triangle is:\n\n");
    for(r=0;r0;r++,n--)
    {
    for(i=0;i0;j--)
    printf("%c",j+64);
    printf("\n");
    }
    return 0;
    }

    ReplyDelete
  3. #include
    int main()
    {
    int i,j,r,n;
    printf("Enter the no. of rows: ");
    scanf("%d",&n);
    printf("The required triangle is:\n\n");
    for(r=0;r0;r++,n--)
    {
    for(i=0;i0;j--)
    printf("%c",j+64);
    printf("\n");
    }
    return 0;
    }

    ReplyDelete
  4. #include
    int main()
    {
    int i,j,r,n;
    printf("Enter the no. of rows: ");
    scanf("%d",&n);
    printf("The required triangle is:\n\n");
    for(r=0;r0;r++,n--)
    {
    for(i=0;i0;j--)
    printf("%c",j+64);
    printf("\n");
    }
    return 0;
    }

    ReplyDelete
  5. #include
    int main()
    {
    int i,j,r,n;
    printf("Enter the no. of rows: ");
    scanf("%d",&n);
    printf("The required triangle is:\n\n");
    for(r=0;r0;r++,n--)
    {
    for(i=0;i0;j--)
    printf("%c",j+64);
    printf("\n");
    }
    return 0;
    }

    ReplyDelete