9.03.2011

13. 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)

                            54321
                            4321
                            321
                            21
                            1
Ans.
/*c program for number triangle pyramid*/

#include<stdio.h>
#include<conio.h>
int main()
{
 int num,c;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(; num>=1; num--)
 {
  for(c=num; c>=1; c--)
     printf("%d",c);
  printf("\n");
 }
 getch();
 return 0;
}

/*************OUTPUT****************
Enter loop repeat number(rows): 5

                            54321
                            4321
                            321
                            21
                            1

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

7 comments:

  1. please write program for ...

    ABCD
    BCDA
    CDAB
    DABC

    ReplyDelete
    Replies
    1. Your required program source code at:

      http://www.cprogrammingcodes.blogspot.in/2012/12/character-rectangle-program.html

      Delete
  2. Please can you try for this .....
    input :abcd
    output:
    a a a a a a a a a
    a b b b b b b b a
    a b c c c c c b a
    a b c d d d c b a
    a b c d d c b a
    a b c d d d c b a
    a b c c c c c b a
    a b b b b b b b a
    a a a a a a a a a

    ReplyDelete
  3. 10 9 8 7 6 5 4 3 2 1 0
    10 9 8 7 5 3 2 1 0
    10 9 8 5 2 1 0
    10 9 5 1 0
    10 5 0
    5
    can anyone help ?

    ReplyDelete
  4. I want the same program by using while loop

    ReplyDelete
    Replies
    1. Above number triangle pyramid using while loop source code as:

      #include"stdio.h"
      #include"conio.h"
      int main()
      {
      int num,c;
      printf("Enter loop repeat number(rows): ");
      scanf("%d",&num);
      while(num>=1)
      {
      c=num;
      while(c>=1)
      {
      printf("%d",c);
      c--;
      }
      num--;
      printf("\n");
      }
      getch();
      return 0;
      }

      Delete