C++ program to print hollow rhombus star pattern

Example

Input

   Enter rows : 5

Output

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

Required Knowledge

Basic C++ programming, For loop, Nested loop

Program

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

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


    for(i=1; i<=rows; i++)
    {
        /* Print trailing spaces */
        for(j=1; j<=rows-i; j++)
        {
            cout<<" ";
        }

        /* Print stars and center spaces */
        for(j=1; j<=rows; j++)
        {
            if(i==1 || i==rows || j==1 || j==rows)
                cout<<"*";
            else
                cout<<" ";
        }
        cout<<"\n";
    }
    return 0;
}

Output

Leave a Reply

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

Share via
Copy link
Powered by Social Snap