You are on page 1of 7

INDEX

SR PRACTICAL NAME DATE SIGN.


N.
Write a program to print Factorial of
1 any number.

Write a program in PHP to print


2 Fibonacci series. 0, 1, 1, 2, 3, 5, 8, 13,
21, 3

Write a program to find whether a


3 number is Armstrong or not.

Write a program to print Reverse of


4 any number.

To check whether a number is Prime or


5 not.

Program to find whether a year is LEAP


6 year or not.

PRACTICAL-1
Write a program to print Factorial of any number
<?php
$number = 6;                   /*number to get factorial */
$fact   = 1;
for($k=1;$k<=$number;++$k)
{
$fact =  $fact*$k;
}
echo "Factorial of $number is ".$fact;
?>

PRACTICAL-2
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;
   
   }
?>

PRACTICAL-3
Write a program to find whether a number is Armstrong or not

// If the sum of cubes of individual digits of a number is equal to the number itslef  then
it is called Armstrong Number.
<?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";
        }
    }
?>

PRACTICAL-4
Write a program to print Reverse of any number

<?php
if(isset($_POST['rev2']))
{
         $rev=0;
         $num=$_POST['rev'];
           
          while($num>=1)
                {
                  $re=$num%10;
                  $rev=$rev*10+$re;
                  $num=$num/10;
                 }
}
?>
<html>
  <head>
      <title>Reverse</title>
 </head>
 <body>
    <table>
         <form name="frm" method="post">
            <tr><td>Number</td><td><input type="text" name="rev"></td></tr>
             <tr><td>Reverse is:</td><td><input type="text" value="<?php
if(isset($_POST['rev2'])){echo $rev;} ?>" name="rev1"></td></tr>
             <tr><td> </td><td><input type="Submit" value="Reverse"
name="rev2"></td></tr>
        </form>
    </table>
 </body>
</html>

PRACTICAL-5
To check whether a number is Prime or not.
<?php
if(is set($_POST['submit']) && $_POST['submit']=='Check' )
{
$check=0;
$num=$_POST['number'];
  for($i=2;$i<=($num/2);$i++)
    {
if($num%$i==0)
        {
         $check++;
         if($check==1)
{
            break;
}
        }
    }
}
?>
<html>
<head>
<title>Prime Number</title>
</head>
<body>
 <table>
   <form name="form" method="post" action="">
        <tr><td>Number:</td><td><input type="text" name="number" /></td></tr>
        <tr><td></td><td><input type="submit" name="submit" value="Check" /></td>
        <td>
         <enter><span>
          <?php if(is set($_POST['sub']))
          {if($check==0)
              {echo "It is a Prime Number";
              }
          else
               {
                echo "It is not a Prime Number";}
               }
          ?>
         </span>
         </enter>
        </td>
        </tr>
   </form>
 </table>
</body>
</html>

PRACTICAL-6
Program to find whether a year is LEAP year or not
<?php
if(is set($_POST['submit']))
{
$year=$_POST['year'];
if($year%4==0)
         {
           $leap="It is a leap year";
         }
     else
        {
          $leap="It is not a leap year";
}
}
?>
<html>
<head>
<title>Leap Year</title>
</head>
<body>
<table>
<form name="form" method="post" action="">
<tr><td>Enter the year:</td><td><input type="text" name="year" /></td></tr>
<tr><td></td> <td><input type="submit" name="submit" value="submit"
/></td>
<td><enter><span>
<?php
if(is set($_POST['submit'])){
echo $leap; }

?>  
</span></center></td></tr>
</form>
</table>
</body>
</html>

You might also like