C Program to Print Triangle of Numbers – Part 2

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.

yashan has written 69 articles

32 thoughts on “C Program to Print Triangle of Numbers – Part 2

    1. raja ganesh says:

      #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.

    1. #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;
      }

    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;
      }

    1. #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;
      }

    1. #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;
      }

    1. YOKESH says:

      #include
      #include
      void main()
      {
      //clear the screen.
      clrscr();
      //declare variable type int
      int i,j,a=1;
      //print triangle
      for(i=1;i<=5;i++)
      {
      for(j=1;j<=i;j++)
      {
      cout<<a<<” “;
      a++;
      }
      cout<<endl;
      }
      //get character
      getch();
      }

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>