A right-angled triangle pattern is a simple triangular arrangement where the right angle is typically at the bottom-left. Printing such patterns helps beginners practice nested loops and alignment in C.
Understanding The Problem
The program should take the number of rows as input and print a right-angled triangle of stars. Each row contains an increasing number of stars, starting from 1 at the top and increasing by 1 in each subsequent row. Nested loops handle the number of stars per row.
Steps to Solve the Problem:
- Take the number of rows from the user.
- Use an outer loop to iterate through each row.
- Use an inner loop to print stars corresponding to the current row number.
- Move to a new line after printing each row.
Solution: Using Nested Loops
Nested loops allow printing stars row by row.
#include <stdio.h>
int main() {
int rows;
printf("Enter number of rows: ");
scanf("%d", &rows);
for(int i = 1; i <= rows; i++) {
for(int j = 1; j <= i; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
In this program, the outer loop controls the rows from 1 to the given number of rows. The inner loop prints stars equal to the current row number. After each row, a newline is printed to form the triangle.

FAQs
Q1: Can we use a character other than *
?
Yes, any symbol can replace *
to create the triangle with a different character.
Q2: Can the triangle be inverted?
Yes, by reversing the outer loop and adjusting the inner loop, you can print an inverted right-angled triangle.
Q3: Can we align the triangle to the right?
Yes, by adding leading spaces in each row, you can print a right-aligned triangle.
Conclusion
This program demonstrates how to print a simple right-angled triangle using nested loops. By controlling the number of stars per row, a clear triangular pattern is formed. This logic can be extended to inverted triangles, hollow triangles, and other geometric patterns.
References & Additional Resources
- C Programming Tutorial – Beginner-friendly tutorials covering loops and pattern printing in C.
- GeeksforGeeks – Pattern Programs in C – Examples of right-angled and other triangle patterns.
- TutorialsPoint – C Loops – Explanation of nested loops and iterative control in C.