Answer to Question #268779 in C++ for mark

Question #268779



Prepare a C++ program of the sample run below.


Square of Stars within a Triangle of Stars. 


1
Expert's answer
2021-11-20T06:43:07-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS