Skip to content

C Program to Print Triangle of Numbers – Part 2

by yashan on August 31st, 2011

Write a program in the C programming language to print the triangle of numbers.  Make a C program to print the following right angled triangle-


1
22
333
4444
55555
666666
7777777
88888888
999999999



This C program is made using by using the nested for loop. Below is the code of the program.-

#include<stdio.h>
void main()
{
     int n,i,n2=0;

     for(i=1;i<=9;i++)
     {
             n2=n2+1;
             for(n=1;n<=i;n++)
             {
                     printf("%d",n2);
             }
             printf("\n");
     }
     getch();
}

Output - Output of the program will be exact as the triangle shown above.

20 Comments
  1. sudhagar permalink

    11 12 13 14 15
    7 8 9 10
    4 5 6
    2 3
    1

  2. Hai.. I need a program to print any given number in triangle…

    Example:

    I am giving input as 5687
    It should print as

    5687
    568
    56
    5
    and also it should print as
    5
    56
    568
    5687

    • raja ganesh permalink

      #include
      #include
      main()
      {
      int num=0,i;
      clrscr();
      printf(“Enter the Number \n”);

      scanf(“%d”,&num);
      while(num)
      {
      printf(“%d\n”,num);
      num=num/10;
      }
      getch();
      }
      It Works above the pgm only.

  3. vishal permalink

    * * * * *
    * * * *
    * * *
    * *
    *

    • #include
      #include

      int main()
      {
      int n;
      printf(“enter the number of rows\n:”);
      scanf(“%d”,&n);
      for(int i=0;i<=n;i++)
      {
      for(int j=1;j<=n-i;j++)
      printf("* ");
      printf("\n");
      }
      getch();
      return 0;
      }

  4. i need a c program to the output
    1
    2 3 4
    5 6 7 8 9

  5. i need a output for
    1
    2 3
    4 5 6
    7 8 9 10

    • #include
      #include

      int main()
      {
      int n,count=0;
      printf(“enter the number of rows\n:”);
      scanf(“%d”,&n);
      for(int i=0;i<n;i++)
      {
      for(int j=0;j<=i;j++)
      printf("%d",++count);
      printf("\n");
      }
      getch();
      return 0;
      }

  6. darshan permalink

    how to print
    12345
    1234
    123
    12
    1

    • #include
      #include

      int main()
      {
      int n,count=1;
      printf(“enter the number of rows\n:”);
      scanf(“%d”,&n);
      for(int i=0;i<=n;i++)
      {
      count=1;
      for(int j=1;j<=n-i;j++)
      printf("%d ",count++);
      printf("\n");
      }
      getch();
      return 0;
      }

  7. Excuse me how to be a code if output
    1
    22
    123
    4444
    12,345
    On the basis if an even number is repeated

    • #include
      #include

      int main()
      {
      int n,count=1;
      printf(“enter the number of rows\n:”);
      scanf(“%d”,&n);
      for(int i=1;i<=n;i++)
      {
      count=1;
      if((i%2)==0)
      {
      for(int j=1;j<=i;j++)
      {
      printf("%d ",i);
      }
      count++;
      }
      else
      {
      for(int j=1;j<=i;j++)
      printf("%d ",count++);
      }
      printf("\n");
      }
      getch();
      return 0;
      }

  8. i need a c program to print

    1
    2 3
    4 5 6
    7 8 9 10

    • #include
      #include

      int main()
      {
      int n,count=0;
      printf(“enter the number of rows\n:”);
      scanf(“%d”,&n);
      for(int i=0;i<n;i++)
      {
      for(int j=0;j<=i;j++)
      printf("%d",++count);
      printf("\n");
      }
      getch();
      return 0;
      }

  9. ashim permalink

    i need a c program to print
    *
    *
    *
    *
    *
    then
    *
    *
    *
    *
    *
    and then
    * *
    * *
    *
    * *
    * *

  10. ashim permalink

    i hasn’t come in the way i have written. Actually the last one is a cross(x) and the first two are the two way cross is made. Can anyone help

  11. muneeb permalink

    hi, I need a code that prints :
    1 3 5 7 9
    1 3 5 7
    1 3 5
    1 3
    1

  12. write a program to print following
    0
    21
    432
    6543
    87654
    1098765

  13. terrin permalink

    i need a output
    1
    1 2
    1 2 3
    1 2 3 4

  14. nathy permalink

    write a program to print this

    1
    2 1 2
    3 2 1 2 3
    4 3 2 1 2 3 4
    5 4 3 2 1 2 3 4 5

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS