View Single Post
Old 08-08-2011, 10:11 AM   #1
sharma.s.prakash
Senior Member
 
sharma.s.prakash's Avatar
 
Join Date: Aug 2011
Posts: 110
Smile Making piramid type shape

PHP Code:
$varNum=1;
while(
$varNum<=9) {
    
$varNum1=1;
     for(
$varSpace=1;$varSpace<=20-$varNum;$varSpace++) {
            echo 
' ';  //if you are running this on browser replace this blank space with &nbsp;
        
}
    while(
$varNum1<=$varNum) {
        
// if you want to creat piramid with character then replace the $varNum1 with desired character like '*' but only
        //  single character to be use
        
echo $varNum1.' ';//if you are running this on browser replace this blank space with &nbsp;
       // echo '& ';//if you are running this on browser replace this blank space with &nbsp;
        
$varNum1++;
    }
    echo 
"\n"// replace \n with <br> if using browser for output
    
$varNum++;

output:
Code:
           1
         1 2
        1 2 3
       1 2 3 4
      1 2 3 4 5 
     1 2 3 4 5 6

Last edited by sharma.s.prakash; 08-08-2011 at 11:55 AM.
sharma.s.prakash is offline   Reply With Quote