* ** *** **** *****
Required knowledge:
Basic C programming, For loopLogic:
Printing right triangle pattern is simple if you got the pattern. If you look to the pattern carefully you will find that you have to print stars in increasing order of rows (i.e. 1 star in first row, followed by 2 stars in second and so on...). To do so we will use the concept of square star pattern with a little change in inner loop code. In the pattern given above the total number of stars(columns) in each row is equal to the row number and we will use this as a termination limit in the inner for loop.Program:
/* * C program to print right triangle star pattern series */ #include <stdio.h> int main() { int i, j, n; //Reads the number of rows to be printed 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/row printf("\n"); } return 0; }
Output
Enter the value of n: 5
*
**
***
****
*****
*
**
***
****
*****
Screenshot:
Happy coding ;)
You may also like
- All star patterns programs index.
- For loop programming exercises and solutions.
- If else programming exercises and solutions.
- C program to print table of any number.
- C program to calculate sum of digits.
- C program to find reverse of any number.
- C program to check whether a number is palindrome or not.
- C program to print Pascal triangle of n rows.
- C program to find factorial of any number.
- C program to print fibonacci series.
- C program to check whether a number is Armstrong number or not.
- C program to check whether a number is Prime number or not.
- C program to print all prime numbers between 1 to n.
- C program to print sum of all prime numbers between 1 to n.