C Program to print right triangle star pattern
Input
5
Result
*
* *
* * *
* * * *
* * * * *
C Program to print right triangle star pattern
Code
#include<stdio.h>
int main(){
int i, j, n;
scanf("%d",&n);
for( i=1; i<=n; i++) //printing the no of lines i.e. n
{
for( j=1; j<=i; j++) //printing the no of columns
{
printf("*");
}
printf("\n");
}
return 0;
}
Explanation
In this program, we are using nested for loop. The outer loop of this program prints the no of the rows or no of lines while the inner for loop prints the no of columns since the serial no of rows = no. of columns like for 1st row there is only 1st column i., j<=i
Also, you can see that there is a newline in the printf function to print star in a new line if the inner for loop becomes false.
Hence, this program prints the right angle star pattern.