C++ program to print reverse right triangle star pattern

Example

Input :

 Input rows: 5 

Output :

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

Required Knowledge

Basic C++ programming, nested loop, if-else,for loop

Program to print inverted right triangle star pattern

#include <iostream>
using namespace std;

int main(){
    int i, j, rows;

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

    /* Iterate through rows */
    for(i=1; i<=rows; i++){
        /* Iterate through columns */
        for(j=i; j<=rows; j++){
            cout<<"*";
        }
       
        /* Move to the next line */
        cout<<"\n";
    }
    return 0;
}
Output:
Enter number of rows: 5
*****
****
***
**
*
  • Save

Leave a Reply

Your email address will not be published. Required fields are marked *

Share via
Copy link
Powered by Social Snap