C++ program to Print Hollow Right Triangle Star Pattern

Example

Input

 Input rows: 5 

Output

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

Required Knowledge

Basic C++ programming, For loop, Nested For loop

Program to print Hollow Right Triangle Star Pattern

#include <iostream>
using namespace std;
 /*
  * Engineer Siddharth Goyal
  * Chandigarh Engineering College, Landran
  *
 */
int main(){
    int i, j, rows;

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

    for(i=1; i<=rows; i++){
        for(j=1; j<=i; j++){ 
            /* 
             * Print star for first column(j==1), 
             * last column(j==i) or last row(i==rows).
             */
            if(j==1 || j==i || i==rows){
                cout<<"*";
            }
            else{
                cout<<" ";
            }
        }

        cout<<"\n";
    }
    return 0;
}
  • Save

Leave a Reply

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

Share via
Copy link
Powered by Social Snap