Print Friendly and PDF
(Square of Asterisks) Write a function that displays at the left margin of the screen a solid square of asterisks whose side is specified in integer parameter side. For example, if side is 4, the function displays the following: **** **** **** ****
(Square of Asterisks) Write a function that displays at the left margin of the screen a solid square of asterisks whose side is specified in integer parameter side. 

For example, if side is 4, the function displays the following:

****

****

****

****

Solution: 
 

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
 
void square ( int );
int side;
 
int main()
{
   cout << "Enter side: ";
   cin >> side;
   square( side );
   return 0;
}
 
//square function
void square( int side )
{
   for( int i = 1; i <= side; i++ )
   {
      for( int j = 1; j <= side; j++)
      {
         cout << "*";
      }
      cout << endl;
   }
}
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: