0

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?

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by arunmagar
0

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.

Edited by arunmagar: spelling mistake

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.