0% found this document useful (0 votes)
2 views12 pages

Practical

The document contains a series of PHP practical exercises aimed at teaching basic programming concepts. Each practical includes a specific aim, the corresponding PHP script, and the expected output. Topics covered include displaying messages, arithmetic operations, number swapping, checking odd/even numbers, finding maximum values, palindrome and Armstrong number checks, Fibonacci series, prime number verification, and calculating student grades.

Uploaded by

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

Practical

The document contains a series of PHP practical exercises aimed at teaching basic programming concepts. Each practical includes a specific aim, the corresponding PHP script, and the expected output. Topics covered include displaying messages, arithmetic operations, number swapping, checking odd/even numbers, finding maximum values, palindrome and Armstrong number checks, Fibonacci series, prime number verification, and calculating student grades.

Uploaded by

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

Practical Set - 1

Practical – 1

Aim :- Write a PHP script to display Welcome Message .

Program :-

<?php
echo"Hello World";
?>

Output :-
Practical Set - 1

Practical – 2

Aim :- Write a PHP script for Addition of two numbers.

Program :-

<?php
$a=10;
$b=20;
$sum=$a+$b;
echo "Addition of $a and $b is $sum";
?>

Output :-
Practical Set - 1

Practical – 3

Aim :- Write a PHP script for Swapping of Three numbers..

Program :-

<?php
$a=10;
$b=20;
$c=30;
echo "Before swap value = $a,$b and $c<br>";
$temp=$a;
$a=$b;
$b=$c;
$c=$temp;
echo "After swap value = $a, $b and $c ";
?>

Output :-
Practical Set - 1

Practical – 4

Aim :- Write a PHP script to demonstrate arithmetic operators, comparison


operator, and logical operator.

Program :-

<?php

$a = 10;
$b = 20;
$c = 15;
$d = true;
$e = false;

echo "Arithmetic operators\n";

$result = $a + $b;
echo "Addition: $a + $b = $result\n";

$result = $b - $a;
echo "Subtraction: $b - $a = $result\n";

$result = $a * $b;
echo "Multiplication: $a * $b = $result\n";

$result = $b / $a;
echo "Division: $b / $a = $result\n";

$result = $b % $a;
echo "Modulus: $b % $a = $result\n";

echo "Comparison operators";

$result = ($a < $b);


echo "Less Than: $a < $b is\n";
Practical Set - 1

$result = ($a > $b);


echo "Greater Than: $a > $b is\n ";

$result = ($a <= $b);


echo "Less Than or Equal To: $a <= $b is \n";

$result = ($a >= $b);


echo "Greater Than or Equal To: $a >= $b is\n ";

$result = ($a == $c);


echo "Equal To: $a == $c is\n ";

$result = ($a != $c);


echo "Not Equal To: $a != $c is \n";

echo "Logical operators";

$result = ($d and $e);


echo "And: $d and $e is\n ";

$result = ($d or $e);


echo "Or: $d or $e is \n";

$result = !$d;
echo "Not: !$d is\n ";

?>

Output :-
Practical Set - 1

Practical – 5

Aim :- Write a PHP script to Check the given number is ODD or EVEN.

Program :-

<?php
$a=6;
if($a%2==0)
{
echo "a is even";
}
else
{
echo "a is odd";
}
?>

Output :-

Practical – 6
Practical Set - 1

Aim :- Write a PHP script to find maximum number out of three given
numbers.

Program :-

<?php
$a="900";
$b="300";
$c="200";
if ($a>$b) {
echo"a is big";
}
else if ($b>$c) {
echo"b is big";
}
else if ($c>$a) {
echo"c is big";
}
else {
echo"c is big";
}
?>
Output :-

Practical –7
Practical Set - 1

Aim :- Write a PHP script to Check the given number is Palindrome or Not.

Program :-

<?php
$number=121;
$temp=$number;
$sum=0;
while($number>0)
{
$rem=$number%10;
$sum=($sum*10)+$rem;
$number=floor($number/10);
}
if($temp==$sum)
echo"it is palidrom";
else
echo"it is not palidrom";
?>

Output :-

Practical – 8
Practical Set - 1

Aim :- Write a PHP script to Check the given number is Armstrong or Not.

Program :-

<?php
$number=152;
$temp=$number;
$sum=0;
while($number>0)
{
$rem=$number%10;
$sum=$sum+($rem*$rem*$rem);
$number=floor($number/10);
}
if($temp==$sum)
echo"it is armstrong";
else
echo"it is not armstrong";
?>

Output :-

Practical – 9
Practical Set - 1

Aim :- Write a PHP script to print Fibonacci series.

Program :-

<?php
echo "print fibonacci series";
$n=10;
$a=0;

$b=1;
echo $a." ".$b." ";
for($i=2; $i<$n; $i++){
$c=$a+$b;
echo $c." ";
$a=$b;
$b=$c;
}
echo "<br>";
?>

Output :-

Practical – 10
Practical Set - 1

Aim :- Write a PHP script to check the given number is prime or not.

Program :-

<?php
$num=29;
$flag=false;
for($i=2;$i<$num;$i++)
{
if($num%$i==0)
{
$flag=true;
break;
}
}
if($flag==true)
{
echo"Not a Prime number";
}
else
{
echo"Prime number";
}
?>
Output :-
Practical Set - 1

Practical – 11

Aim :- Write PHP Script to calculate total marks of student and display grade.

Program :-

<? php
$Maths=75;
$Science=80;
$English=90;
$Hindi=88; echo"Maths:$Maths<br>Science:
{Science<br>English:$English<br>Hindi:
$Hindi<br>";
$total=$Maths+$Science+$English+$Hindi;
echo "Total Marks: Stotal<br>";
$percentage=$total*100/400; echo"Percentage:$percentage";
?>

Output :-

You might also like