Pattern 24 : C Program to print triangle Number pattern using for loops

Spread the love

Program to print Triangle number pattern :

Let’s write a C Program to print the Triangle number pattern. Program will take one input number from the user and prints the pattern with that many number of rows.

Here is a Sample expected output, When user input value is 5

Example:

Enter how many rows you want: 5
 1
 1 2
 1 2 3
 1 2 3 4
 1 2 3 4 5

To print the given pattern, We are going to use two for loops. The Outer for loop and Inner for loop. The Outer for loop is used to print the rows and the inner for loop is used to print the columns.

So at each iteration of Outer for loop, The inner for loop will executes the given rows number of times.

The main logic is to stop printing the numbers when we reach the (j=i)  Here  'i'  outer loop iterator.  'j'  inner loop iterator. So stopping when both  i and j  becomes equal, We are creating the diagonal shape of our Triangle pattern.

Triangle number pattern Program:

Program Output:

Triangle-number-pattern-in-c-language

Similar Number Patterns:

Similar Star pattern programs :

Venkat

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

You may also like...

Leave a Reply