C Program to Print Triangle of Numbers – Part 1

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
12
123
1234
12345
123456
1234567
12345678
123456789


Make this program by using the nested for loop. Below is the solution of the program.-

void main()
{
     int n, i;

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

Output – Output of the program will be same as the triangle made above.

yashan has written 69 articles

14 thoughts on “C Program to Print Triangle of Numbers – Part 1

    1. sriram says:

      #include
      main()
      {
      int i,j,k,n;

      printf(“Enter number of rows of the triangle \n”);
      scanf(“%d”,&n);

      for(i=1;i<=n;i++)
      {

      for(k=1;k<=(2*i)-1;k++)
      {
      j=i;
      printf("%d",j);
      j++;
      }
      printf("\n");
      }
      getch();
      }

    2. Ashok kumar srivastava says:

      #include

      int main()
      {
      int n, i, c, a = 1;

      printf(“Enter the number of rows of Floyd’s triangle to print\n”);
      scanf(“%d”, &n);

      for (i = 1; i <= n; i++)
      {
      for (c = 1; c <= i; c++)
      {
      printf("%d ",a);
      a++;
      }
      printf("\n");
      }

      return 0;
      }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>