Prepare a C++ program of the sample run below.
Square of Stars within a Triangle of Stars.
#include<iostream>
using namespace std;
int main()
{
int rows, i, j, gap;
cout << "Enter number of rows: ";
cin >> rows;
for(i = 1; i <= rows; i++)
{
for (gap = i; gap < rows; gap++)
cout << " ";
for(j = 1; j <= (2 * rows - 1); j++)
{
if(i == rows || j == 1 || j == 2*i - 1)
cout << "*";
else
cout << " ";
}
cout << "\n";
}
return 0;
}
Comments
Leave a comment