C++ program to print right triangle star pattern

Write a C program to print right triangle star pattern series using for loop. How to print right triangle star pattern series of n rows in C programming. Logic to print right triangle star pattern in C.

Example

Input

 Input number of rows: 5 

Output

*
**
***
****
*****

Required knowledge

Basic C programming, If else, For loop, Nested loop

Program to print right triangle star pattern

#include <iostream>
using namespace std;
int main(){
    int i, j, n;

    /* Input number of rows from user */
    cout<<"Enter value of n: ";
    cin>>n;

    for(i=1; i<=n; i++){
        /* Print i number of stars */
        for(j=1; j<=i; j++){
            cout<<"*";
        }
        /* Move to next line */
        cout<<"\n";
    }
    return 0;
}

Output

  • Save

Share via
Copy link
Powered by Social Snap