C++ program to print rhombus star pattern

Example

Input

    Enter rows: 5 

Output

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

Required Knowledge

Basic C++ programming, For loop, Nested loop

Making Solid Rhombus is similar to making a solid square rather than the concept that for each ith row we have n-i blank spaces before stars as:
– – – ****
– – ****
– ****
****

Program

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

    cout<<"Enter rows: ";
    cin>>rows;

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

        /* Print stars after spaces */
        for(j=1; j<=rows; j++)
        {
            cout<<"*";
        }

        /* Move to the next line */
        cout<<"\n";
    }
    return 0;
}

Output

Enter 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