hi guys i have to Write Square(n) function that prints a square of different sizes. The size of the
square is given as input to the user.
Please enter an integer value n: 10
***********************
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
***********************


can anyone help?

hi guys i have to Write Square(n) function that prints a square of different sizes. The size of the
square is given as input to the user.
Please enter an integer value n: 10
***********************
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
***********************


can anyone help?

Hi ,

Following code may help you.It is tested on terminal.Its working fine.If you want it to show correct output on web browser.Please replace "\n" by "<br />" and
" " (space) by "&nbsp;&nbsp;"

For user input you can make gui using html.

Here it is code

<?php
$n=10;
for($i=0;$i<$n;$i++)
{
  if($i==0)
  {
         //print horizontal *
         for($j=0;$j<$n;$j++)
         {
              echo "*"; 
         }
           
         echo "\n"; 
   }
   else if($i==($n-1))
   {
         //print horizontal *
          for($j=0;$j<$n;$j++)
         {
              echo "*"; 
         }
           
         echo "\n"; 
    }
    else
    {
         for($j=0;$j<$n;$j++)
         {
             if($j==0 || $j==($n-1))
              echo "*";
             else
              echo " ";
         }
           
         echo "\n"; 

    }

If you have any doubt.Please let me know.
If this is your solution Please make this thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.