C program to print right triangle star pattern

Write a C program to print right triangle star(*) pattern series using for loop. How to print right triangle star pattern series of n rows using for loop in C programming. Logic to print right triangle star pattern in C.

Example

Input

Input number of rows: 5

Output

Required knowledge

Basic C programming, For loop

Logic to print right triangle star pattern

Printing right triangle pattern is simple if you got the pattern. If you look to the pattern carefully you will find that you have to print stars in increasing order of rows (i.e. 1 star in first row, followed by 2 stars in second and so on...). To print so we will use the concept of square star pattern with a little change in inner loop code.
In the pattern given total number of stars per column in each row is equal to the current row number and we will use this as a termination limit in the inner for loop.

Program to print right triangle star pattern

/*
 * C program to print right triangle star pattern series
 */

#include <stdio.h>

int main()
{
    int i, j, n;

    // Input number of rows from user
    printf("Enter value of n: ");
    scanf("%d", &n);

    for(i=1; i<=n; i++)
    {
        // Print i number of stars
        for(j=1; j<=i; j++)
        {
            printf("*");
        }

        // Move to next line/row
        printf("\n");
    }

    return 0;
}

Output

Enter the value of n: 5
*
**
***
****
*****

Happy coding 😉

Write your doubts or suggestion. I will try my best to help. You must escape source code before commenting. To format your source code paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>