* ** *** **** *****
/*
* C program to print right triangle star pattern series
* atnyla.com
*/
#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 */
printf("\n");
}
return 0;
}
Enter the value of n: 5
*
**
***
****
*****
Basic C programming, If else, For loop, Nested loop
* ** *** **** *****
If you look at the pattern carefully you will find that stars are in increasing order of rows (i.e. 1 star in the first row, followed by 2 stars in second and so on).
Step by step descriptive logic to print right triangle star pattern.
for(i=1; i<=N; i++).for(j=1; j<=i; j++). Inside the inner loop print star.First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.