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 70 articles

98 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. Rita says:

        Woah, sounds like it was a fantastic event! As a blogger, I never get invited to events where I can visit the factories and understand how the products are produced, which is actually very interesting! Are you planning to organize more bl718ers&#g2go; events in the future?

    1. Kunal S Kasar says:

      //Source Code

      //Example 7: Program to print pyramid using numbers
      //
      // enter rows
      //5
      //output :-
      //
      //1
      //2 3 4
      //3 4 5 6 7
      //4 5 6 7 8 7 6
      //5 6 7 8 9 8 7 6 5

      #include
      #include
      int main()
      {
      int i, j,k, rows;
      int count = 0, count1 = 0;

      printf(“enter rows \n”);
      scanf(“%d”,&rows);

      printf(“output :- \n\n”);

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

      while(k != 2*i-1)
      {
      if (count <= rows-1)
      {
      printf("%d ", i+k);
      ++count;
      }
      else
      {
      ++count1;
      printf("%d ", (i+k-2*count1));
      }
      ++k;
      }
      count1 = count = k = 0;

      printf("\n");
      }
      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;
      }

    2. Martha says:

      The only thing i saw wrong during the gaa,wems a man dressed in blue behind home plate trying to immetate an umpire. keep your head up Jason, somthing good will come out of this. All of us are behind you 100%. And so are your ball players.

    3. http://www./ says:

      Totally agree.At this stage of the economic cycle to be also running a Budget Deficit of 3% GDP is a sure sign that monetary and fiscalpolicy is too lax.Further easing of interest rates without severe control of public expenditure will create temporary relief at the cost of medium term crisis and longer term decline.We need anotherMargaret Thatcher to shake things up!

    4. http://www./ says:

      Sedikit banyak aku temukan jawabannya disini, kenapa wpku dulu kok PRnya anjlok dr 3 ke 0 dan gak naik2 lg. Salam kenal Mbak…… .-= masnur´s selesai [nulis] ..Ngabuburit Nyoookkk….. =-.Lha, kok bisa ya? Jualan link di review nggak? PakDhe Cholik juga pernah tuh, tiba-tiba amblas PRnya.

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

    2. Nikhil Gupta says:

      # include”stdio.h”
      # include”conio.h”
      main ()
      {
      int i,j;
      clrscr ();
      for (i=5;i>=1;i–)
      {
      for (j=1;j <=i;j++)
      {
      printf ("%d",j);
      }
      printf ("/n");
      }
      getch ();
      }

    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. Hollie says:

        Amanda comentou em 9 de novembro de 2012 às 14:27. Oi Jana!!Gostei tanto do posto do primeiro emprego que estou lendo suas publicações das mais novas para as mais antigas. Seu jeito de escrever me encanta e sua percepção de mundo é profunda e descomplicada ao mesmo tempo. Pa!EÃb©ns!!rastava um pouco afastada do petiscos e seus posts me deram vontade de voltar…Bjos

    2. http://www./ says:

      Hey Roger,When does your holiday start? Gotta let the Burr’s crew know when not to expect updates. Great read so far. I’m still in the water up here. Think I’m getting hauled on Wednesday. Paul took a ride to Ledge Light today ’cause the day was so nice. Stay Safe, Lauri (Burr’s)

    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. Debra says:

        Pero sigue sin despejar el debate de “cómo es posible asignar un porcentaje de reducción a una determinada contramedida que permita calcular el riesgo remanente tras su ap;i8ación&#c221l. Es algo tan subjetivo el asignar un porcentaje de reducción, que devalua cualquier cálculo del riesgo residual…

    2. Cherry says:

      Trevor, I don’t want to go on and on about how you’re the most amazing comic gercts/aiuon, cause I’m sure that gets old. But I was wondering, random as this is gonna sound, if you could pick like 10 or 15 songs on the soundtrack to your life, which would they be?

    3. OMG these are great, Love you both and love these pictures! Britt you did an amazing job!!! LOVE LOVE LOVE THEM.They are all so beautiful! But stop working, nobody expects you to be working right now PS.Is it awkward when your teacher is on the computer during work time and crying? Probably!

    4. Admiring the commitment you put into your blog and detailed information you present. It’s good to come across a blog every once in a while that isn’t the same unwanted rehashed material. Wonderful read! I’ve bookmarked your site and I’m adding your RSS feeds to my Google account.

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

    2. Dinesh Murugavel says:

      #include
      int main()
      {
      int i,j,n,a=0,b=1;
      printf(“Enter the no. of lines:\n”);
      scanf(“%d\n”,&n);
      //printf(“%d\n”,n);
      for(i=0;i<(2*n);i++)
      {
      for(j=0;j<a;j++)
      {
      printf("%d ",b);
      b++;
      }
      printf("\n");
      b=1;
      if(i<n)
      {
      //printf("%d\n",n+1);
      a++;
      }
      else
      {
      //printf("%d\n",i);
      a–;
      }
      }
      return 0;
      }

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

    2. Dinesh Murugavel says:

      #include
      int main()
      {
      int i,j,n,a=1,b;
      scanf(“%d\n”,&n);
      for(i=1;i<=n;i++)
      {
      if(i%2!=0)
      {
      b=1;
      for(j=0;j<a;j++)
      {
      printf("%d ",b);
      b=b+2;
      }
      }
      else
      {
      b=2;
      for(j=0;j<a;j++)
      {
      printf("%d ",b);
      b=b+2;
      }
      }
      a=a+2;
      printf("\n");
      }
      return 0;
      }

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

    1. Doc says:

      Après avoir parlé avec des res­pon­sables de Sigma Suisse, il sem­ble­rait que l’effet ampli­fi­ca­teur des forums est fonc­tionné de façon assez impor­tante. Ils ont bien eu quelques retours en 2011 (moins de 4) et aucun en 2012. ca depend du nombre d’exemplaires vendu si seulement 4 ont été vendu le pourcentage de retours est imra#tont&p8230;Pour les photos de meeting aérien il donne quoi, son poids est il un frein à une utilisation sur un aérodrome ?

    1. ritengo che nell’ambito di un continuo processo di crescita, quale deve essere il percorso musicale di una band, la critica costruttiva, o solo un’opinione fuori dal coro, ci possa e ci debba stare…il disco intanto continua a girare ed a non convincermi….credo che 14,80 buone ragioni mi diano la libertà di ribadire il mio scarso entusiasmo per l’ultimo lavoro discografico di uno dei miei gruppi preferiti!

  1. Katherine says:

    Naomi Bloom / Donald, if yov728#1&;ue been reading my columns in HRO Today, beginning in early 2003, and now in HRO Europe, you’d have seen all of your points above laid out in detail, and many more, along with the details of how to achieve the essential software platform for BPO. And in the work I’ve been doing with the providers, beginning with the formation of Exult and working through most of the majors, to every market segment, I’ve been a very strong proponent for these same ideas. If having access to these working papers would be helpful to you, just let me know.

Cancel reply

Leave a Reply to vishal

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>