PHP 2nd ia
6th program
<?php
date_default_timezone_set('Asia/calcutta');
$Hour=date('G');
echo "The current time is(in 24-hour format):".$Hour."<br>";
if($Hour<12)
{
echo "Good Morning";
}
else if($Hour>=12 && $Hour<18)
{
echo "Good Afternoon";
}
else if($Hour>=18 && $Hour<24)
{
echo "Good Evening";
}
else
{
echo "Good Night";
}
?>
7th program
<?php
$gcd="";
$lcm="";
if(isset($_POST['submit']))
{
$a=$_POST['first'];
$b=$_POST['second'];
function GCD($a,$b)
{
if($b==0)
{
return $a;
}
else
{
return gcd($b,$a%$b);
}
}
$gcd=GCD($a,$b);
$lcm=($a*$b)/$gcd;
}
?>
<html>
<head>
<title>GCD and Lcm</title>
</head>
<body>
<center>
<form method="post">
<h1>GCD and LCM Calculator</h1>
<label>Enter first number:</label>
<input type="text" name="first"/><br><br>
<label>Enter second number:</label>
<input type="text" name="second"/><br><br>
<input type="submit" name="submit" value="calculate"/>
<br><br>
GCD is:<input type="text" value="<?php echo $gcd;?>"readonly><br><br>
Lcm is:<input type="text" value="<?php echo $lcm;?>"readonly><br><br>
</form>
</center>
</body>
</html>
8th program
<?php
class ArithmeticOperation
{
public $a=0;
public $b=0;
function __construct()
{
$this->a=10;
$this->b=20;
}
function add()
{
$sum=$this->a+$this->b;
echo "the addition of a and b is:".$sum;
}
function __destruct()
{
echo "<br>destruct() function is called";
}
function sub()
{
$sub=$this->a-$this->b;
echo "<br>the subtraction of a and b is:".$sub;
}
}
$object1=new ArithmeticOperation();
$object1->add();
$object1->sub();
unset($object1);
?>
Comments
Post a Comment