- Write a program in C to print right triangle star (*) pattern of n rows using for loop.
- Write a C program to print a right angles triangle pattern of star (*) character using loops.

#### Required Knowledge

**Algorithm to print right triangle star pattern using loop**

- Take the number of rows(N) of right triangle as input from user using scanf function.
**Number of stars in K**. 1^{th}row is always K^{st}row contains 1 star, 2^{nd}row contains 2 stars, 3^{rd}row contains 3 stars. In general, K^{th}row contains K stars.- We will use two for loops to print right triangle star pattern.
- For a right triangle star pattern of N rows, outer for loop will iterate N time. Each iteration of outer loop will print one row of the pattern.
- For K
^{th}row of right triangle pattern, inner loop will iterate K times. Each iteration of inner loop will print one star (*).

Here is the matrix representation of the triangle star pattern. The row numbers are represented by i whereas column numbers are represented by j.

## C program to print right triangle star pattern

#include<stdio.h> int main() { int i,j,rows; printf("Enter the number of rows\n"); scanf("%d", &rows); for(i = 0; i < rows; i++) { /* Prints one row of triangle */ for(j = 0; j <= i; ++j) { printf("* "); } /* move to next row */ printf("\n"); } return 0; }Output

Enter the number of rows 6 * * * * * * * * * * * * * * * * * * * * *

**Related Topics**