Right Triangle Pattern
A Right Triangle Star Pattern comprises rows where each row has an increasing number of stars which form a triangle shape which is lean towards the right side. The star are lie at the left side of each row, with subsequent rows having more stars than the preceding ones.
Output
Enter the number of rows: 5
*
* *
* * *
* * * *
* * * * *
Free Hand-Written Notes
Codes – Right Triangle Pattern
#include <stdio.h> int main() { int rows; printf("Enter the number of rows: "); scanf("%d", &rows); for (int i = 1; i <= rows; i++) { // Print stars for (int j = 1; j <= i; j++) { printf("* "); } printf("\n"); } return 0; }
Codes Explanation
- Here first the program prompts for the user to enter the number of rows for the right triangle.
- Then it will iterates through each row using a “
for
“ loop. - After iterate the it will within each row, it prints stars (
*
) using another nestedfor
loop. - The number of stars in each row increases with the row number.
- Finally, it moves to the next line to start the next row.