Friday 28 July 2017

Write a program to make a chess:

Write a program to make a chess:












  <table width="270px" cellspacing="0px" cellpadding="0px" border="1px">
   <!-- cell 270px wide (8 columns x 60px) -->  
      <?php  
      for($row=1;$row<=8;$row++)  
      {  
          echo "<tr>";  
          for($col=1;$col<=8;$col++)  
          {  
          $total=$row+$col;  
          if($total%2==0)  
          {  
          echo "<td height=30px width=30px bgcolor=#FFFFFF></td>";  
          }  
          else  
          {  
          echo "<td height=30px width=30px bgcolor=#000000></td>";  
          }  
          }  
          echo "</tr>";  
    }  
          ?>  
  </table>  

Program to print below format...

(1) Program to print below format
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *



<?php

   $rows=5; // number of row
      for($i=1;$i<=$rows;$i++)
        {
 
           for($j=1;$j<=$i;$j++)
              {
                echo "*";
              }
            echo "<br />";
        }




?> 





(2 ) Write a program to print the below format :
1 5 9
2 6 10
3 7 11
4 8 12



<?php

for($i=1;$i<=4;$i++)
{
 $i1=$i+4;
 $i2=$i+8;
echo $i." ".$i1." ".$i2;
echo "<br />";
}


?>
 
 
(3) Write a program for this Pattern:
 
*****
*      *
*      *
*      *
*****
 
<?php
for($i = 1; $i<=5; $i++){
            for($j = 1; $j<=5; $j++){
               if($i == 1 || $i == 5){
                   echo "*";
               }
               else if($j == 1 || $j == 5){
                   echo "*";
               }
               else {
                   echo "&nbsp;&nbsp;";
               }
               
            }
            echo "<br/>";
}
?>
 

 
 
 
 
 
 


Program to print below format..

Program to print below format.
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1





<?php
   $rows=5;  // number of row
   for($i=$rows;$i>=1;--$i)
     {
         for($j=1;$j<=$i;++$j)
         {
            echo $j;
         }
     echo "<br />";
     }
 ?>
 

Program to print the below format.

Program to print the below format
* * * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *



<?php


   $rows=5;  // number of row enter.
   for($i=$rows;$i>=1;--$i)
     {
         for($space=0;$space<$rows-$i;++$space)
            echo "  ";
         for($j=$i;$j<=2*$i-1;++$j)
           echo "* ";
         for($j=0;$j<$i-1;++$j)
             echo "* ";
         echo "<br />";
     }



?>

Program to find year is LEAP year or not.


<?php
    $year=2017;
    if($year%4==0)
          {
            $leap="It is a leap year";
          }
      else
         {
           $leap="It is not a leap year";
        }
 ?>

Write a program to print Fibonacci series

Write a program to print Fibonacci series

<?php
$fibo=array(0,1);
$num=4;
     for($i=2;$i<=$num-1;$i++)
{
       $fibo[$i]=$fibo[$i-1]+$fibo[$i-2];
      }
?>

To check whether a number is Prime or not.

<?php

   $check=0;
   $num=$_POST['number'];
   for($i=2;$i<=($num/2);$i++)
     { 
       if($num%$i==0)
         {
          $check++;
          if($check==1)
          {
             break;
          }
         }
     }

?>

Write a program to print Reverse in php

<?php
         $rev=0;
         $num=4;
         
          while($num>=1)
                {
                  $re=$num%10;
                  $rev=$rev*10+$re;
                  $num=$num/10;
                 }

?>

Write a program to find whether a number is Armstrong or not in php.


<?php
if(isset($_POST['number']) && $_POST['number']!='') 
    {  
      
        $number = $_POST[ 'number' ];      // get the number entered by user
     
        $temp = $number;
        $sum  = 0;
     
        while($temp != 0 )
        {
            $remainder   = $temp % 10; //find reminder
            $sum         = $sum + ( $remainder * $remainder * $remainder );
            $temp        = $temp / 10;

       }
        if( $number == $sum )
        {
            echo "$number is an Armstrong Number";
        }else
        {
            echo "$number is not an Armstrong Number";
        }
    }
?>

Write a program in PHP to print Fibonacci series . 0, 1, 1, 2, 3, 5, 8, 13, 21, 34

<?PHP 
   $first = 0;
   $second = 1;
   echo $first.'&nbsp;,';
   echo $second.'&nbsp;,';
  
  for($limit=0;$limit<10;$limit++)
   {
     $third = $first+$second;
     echo $third.'&nbsp;,';;
     $first = $second;
     $second = $third;

   
   }
?>