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

50 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. inayat says:

      int temp = 0;
      for (int i = 5; i >= 1; i–)
      {
      temp = 0;
      for (int j = 1; j <= i; j++)
      {

      Console.Write(j+temp);
      temp++;

      }

      Console.WriteLine();
      }

      Console.ReadKey();

    1. inayat says:

      int temp = 0;
      for (int i = 0; i <= 5; i++)
      {
      temp = i + i;
      for (int j = 0; j <= i; j++)
      {

      Console.Write(j+temp);

      temp = temp – 2;
      }

      Console.WriteLine();
      }

      Console.ReadKey();

    1. inayat says:

      for (int i = 1; i = i; j–)
      {
      Console.Write(i);
      }
      Console.WriteLine();
      }
      for (int i = 2; i >= 1; i–)
      {
      for (int j = 1; j <= i; j++)
      {
      Console.Write(i);
      }
      Console.WriteLine();
      }
      Console.ReadKey();

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

    1. inayat says:

      int temp = 0;
      for (int i = 1; i <= 5; i++)

      {

      for (int j = 1; j <= i; j++)
      {
      Console.Write(j + temp);
      }
      temp = temp + i;
      Console.WriteLine();
      }
      Console.ReadKey();

    1. inayat says:

      for (int i = 5; i >= 1; i–)
      {
      for (int j = i; j >=1; j–)
      {
      Console.Write(“*”);
      }
      Console.WriteLine();
      }
      for (int i = 1; i <= 5; i++)
      {
      for (int j = 1; j <= i; j++)
      {
      Console.Write("*");
      }
      Console.WriteLine();
      }
      Console.ReadKey();

      1. inayat says:

        for (int i = 1; i <= 5; i++)
        {
        for (int j = 1; j = 1; i–)
        {
        for (int j = 1; j <= i; j++)
        {
        Console.Write(j);
        }
        Console.WriteLine();
        }
        Console.ReadKey();

        1. inayat says:

          for (int i = 1; i <=5 ; i++)
          {
          for (int j = 1; j = 1; i–)
          {
          for (int j = 1; j <= i; j++)
          {
          Console.Write(j);
          }
          Console.WriteLine();
          }
          Console.ReadKey();

    1. inayat says:

      for (int i = 1; i <= 5; i++)
      {
      for (int j = 1; j = 1; i–)
      {
      for (int j = 1; j <= i; j++)
      {

      Console.Write(j);
      }
      Console.WriteLine();
      }
      Console.ReadKey();

    1. inayat says:

      for (int i = 1; i <=5 ; i++)
      {
      if(i==5)
      {
      for (int j = 1; j <= i*2; j++)
      {
      Console.Write("*");
      }
      }
      else
      {
      for (int j = 1; j = 1; i–)
      {
      for (int j = 1; j <= i; j++)
      {
      Console.Write("*");
      }
      Console.WriteLine();
      }
      Console.ReadKey();

      1. inayat says:

        for (int i = 1; i <=5 ; i++)
        {
        if(i==5)
        {
        for (int j = 1; j <= i*2; j++)
        {
        Console.Write("*");
        }
        }
        else
        {
        for (int j = 1; j = 1; i–)
        {
        for (int j = 1; j <= i; j++)
        {
        Console.Write("*");
        }
        Console.WriteLine();
        }

    2. inayat says:

      for (int i = 1; i <=5 ; i++)
      {
      if(i==5)
      {
      for (int j = 1; j <= i*2; j++)
      {
      Console.Write("*");
      }
      }
      else
      {
      for (int j = 1; j = 1; k–)
      {
      for (int M = 1; M <= k; M++)
      {
      Console.Write("*");
      }
      Console.WriteLine();
      }

    1. inayat says:

      for (int i = 1; i <= 4; i++)
      {
      for (int j = 1; j = 1; i–)
      {
      for (int j = 1; j <= i; j++)
      {
      Console.Write("*");
      }
      Console.WriteLine();
      }
      Console.ReadKey();

    1. inayat says:

      Console.Write(“Enter the number of rown you wanna print into the pyramid:”);
      int x = Convert.ToInt32(Console.ReadLine());
      int temp = 0;
      int temp1 = 0;
      for (int i = 0; i <= x; i+=1)
      {
      temp = 0;
      temp1 = 2;
      for (int j =0 ; j <= i*2; j++)
      {
      //check odd number
      if (i % 2 == 0)
      {
      temp = temp + 1;
      Console.Write((j + temp) + " ");
      }
      else
      {

      Console.Write((j + temp1) + " ");
      temp1++;
      }
      }
      Console.WriteLine();
      }
      Console.ReadLine();

    1. inayat says:

      int temp = 0;
      for (int i = 1; i <= 4; i++)

      {

      for (int j = 1; j <= i; j++)
      {
      Console.Write(j + temp);
      }
      temp = temp + i;
      Console.WriteLine();
      }
      Console.ReadKey();

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>