Exam Help.
Exam Help.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>q1</title>
</head>
<body>
<?php
$num=5;
$c=0;
$i=1;
while($num>=$i){
?>
</body>
</html>
q3. write a php program to print the no. is armstrong or not
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>q3</title>
</head>
<body>
<?php
$num=153;
$c=$num;
$arm=0;
$r;
while($num>0){
$r=$num%10;
$arm=($r*$r*$r)+$arm;
$num=$num/10;
}
if($c===$arm){
echo("armstrong number");
}
else{
echo("not a armstrong number");
}
?>
</body>
</html>
q4.write a php program to reverse a no.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>q4</title>
</head>
<body>
<?php
$num=123;
$sum=0;
$r=0;
while($num>0){
$r=$num%10;
$sum=($sum*10)+$r;
$num=$num/10;
}
echo($num);
?>
</body>
</html>
q5.write a php program to swap 2 no. without using 3rd variable
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>q5</title>
</head>
<body>
<?php
$a=10;
$b=20;
$a=$a +$b;
$b=$a -$b;
$a=$a -$b;
echo ($a);
echo (&b);
?>
</body>
</html>
Experiment 6:-
1.find the greatest among 2 no. using php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>question 1</title>
</head>
<body>
<?php
$a=10;
$b=20;
if($a>$b){
echo ("a");
}
else{
echo("b");
}
?>
</body>
</html>
2. find x to the power y using function
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>q2</title>
</head>
<body>
<?php
$a=pow(3,4);
echo($a);
?>
</body>
</html>
3.print 1 to n number using for loop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>loop</title>
</head>
<body>
<?php
$num=10;
for($i=1;$i<=$num;$i++)
{
echo(" ".$i);
}
?>
</body>
</html>
4. write a php program to read a file.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>q4</title>
</head>
<body>
<?php
$file=fopen("file1.txt","r");
fread($file,filesize("file1.txt"));
echo($file);
?>
</body>
</html>
5. write a php program to connect with the data base.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
</body>
</html>