0% found this document useful (0 votes)
15 views4 pages

Exam Help.

The document contains multiple PHP programs addressing various tasks such as checking if a number is prime, generating Fibonacci series, determining if a number is an Armstrong number, reversing a number, and swapping two numbers without a third variable. It also includes programs to find the greatest of two numbers, calculate power using a function, print numbers from 1 to n, read a file, and connect to a database. Each task is presented with HTML structure and PHP code snippets.

Uploaded by

mrrandom663
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Exam Help.

The document contains multiple PHP programs addressing various tasks such as checking if a number is prime, generating Fibonacci series, determining if a number is an Armstrong number, reversing a number, and swapping two numbers without a third variable. It also includes programs to find the greatest of two numbers, calculate power using a function, print numbers from 1 to n, read a file, and connect to a database. Each task is presented with HTML structure and PHP code snippets.

Uploaded by

mrrandom663
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment 5:-

q1. write a php program to find the no. is prime or not

<!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){

if($num % $i === 0){


$c++;
}
$i++;
}
if($c===2){
echo("prime number");
}
else{
echo("not prime");
}
?>
</body>
</html>
q2. write a php program to print first 10 Fibonacci series
<!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
$n=10;
$a=0;
$b=1;
$c=0;
for($i=0;$i<=$n;$i++){
$c=$a+$b;
echo($c);
$a=$b;
$b=$c;
}

?>
</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 = "";

$conn = new mysqli($servername, $username, $password);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
</body>
</html>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy