C++ Program To Print Rhombus and Hollow Rhombus Pattern

 

C++ Program To Print Rhombus and Hollow Rhombus Pattern, Rhombus pattern, Hollow Rhombus Pattern, Pattern problem, pattern

(i) Rhombus Pattern


Program:

#include <iostream>
using namespace std;

int main ()
{
  int n;
  cout << "Enter number of rows: ";
  cin >> n;

  for (int i = 1; i <= n; i++)	//loop to change line
    {
      for (int j = 1; j <= n - i; j++)	//loop to print spaces
	    cout << "  ";

      for (int k = 1; k <= n; k++)	//loop to print *
	    cout << "* ";

      cout << endl; //after printing every row jump to next row
    }
  return 0;
}

Output:

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

(ii) Hollow Rhombus Pattern


Program:

#include <iostream>
using namespace std;

int main ()
{
  int n;
  cout << "Enter number of rows: ";
  cin >> n;

  for (int i = 1; i <= n; i++)	//loop to change line
    {
      for (int j = 1; j <= n - i ; j++)	//loop to print spaces
	    cout << "  ";

      for (int k = 1; k <= n; k++)	//loop to print *
	  {
	    if (i == 1 || i == n || k == 1 || k == n)
	        cout << "* ";

	    else
	        cout << "  ";
	  }
      cout << endl;		//after printing every row jump to next row
    }
  return 0;
}

Output:

     * * * * *
    *       *
   *       *
  * * * * *
C++ Program To Print Rhombus and Hollow Rhombus Pattern C++ Program To Print Rhombus and Hollow Rhombus Pattern Reviewed by Beast Coder on February 14, 2021 Rating: 5

No comments:

Powered by Blogger.