0% found this document useful (0 votes)
9 views

12th C a Practical Exam EM 2025

The document outlines practical examination questions for PHP programming, including scripts for comparing numbers, using switch statements, printing numbers with loops, and performing arithmetic operations. Each question provides a clear aim, procedure, and expected output for the PHP scripts. The document is prepared by B. Mohamed Yousuf, a PG Assistant in Computer Science.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

12th C a Practical Exam EM 2025

The document outlines practical examination questions for PHP programming, including scripts for comparing numbers, using switch statements, printing numbers with loops, and performing arithmetic operations. Each question provides a clear aim, procedure, and expected output for the PHP scripts. The document is prepared by B. Mohamed Yousuf, a PG Assistant in Computer Science.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

GOVT PRACTICAL EXAMINATION – 2024-2025

NAME :

REG.NO :

STD :

SUBJECT :

n
l.i
DATE :

SESSION :

BATCH :
da
ka
vi
al
.k
w
w
w
QUESTION - 1

Program: 6
Write a PHP script that stores a value in a variable and then checks if it is less than,
equal to or greater than 5 ?

AIM:
 To check if a variable is less than, equal to, or greater than 5 and output the corresponding
message.
PROCEDURE:
1. Open a new file in your text editor (Notepad).
2. Type the following PHP script.
3. Save the file in the following format “filename.php”. Let us take p2.php for an example.
4. Save the file p2.php in the file saving path - c:\wamp64\www\
5. Make sure Apache is started in Wampserver.
6. Go to the browser and type:-http://localhost/p2.php In your web browser, you should see

n
the results of your script.

l.i
PHP SCRIPT:
<?php
$num = 10;
if ($num< 5)
{ da
ka
echo “The number is less than 5.”;
}
elseif ($num> 5)
vi

{
echo “The number is greater than 5.”;
al

}
else
.k

{
echo “The number is equal to 5.”;
w

}
?>
w

OUTPUT:
 The number is greater than 5.
w

RESULT:
 The expected output is achieved.

[OR]

Program: 1 [ PAGE FORMATTING ]

PREPARED BY..., B.MOHAMED YOUSUF M.C.A., B.Ed.., (PG ASST IN COMPUTER SCIENCE)
QUESTION - 2

Program: 7
Write a PHP script that takes a number and outputs the corresponding text for the
number using switch statement.

AIM:
 To output the corresponding text for a number using a switch statement.
PROCEDURE:
1. Open a new file in your text editor (Notepad).
2. Type the following PHP script.
3. Save the file in the following format “filename.php”. Let us take p3.php for an example.
4. Save the file p3.php in the file saving path - c:\wamp64\www\
5. Make sure Apache is started in Wampserver.
6. Go to the browser and type:-http://localhost/p3.php In your web browser, you should see
the results of your script.

n
PHP SCRIPT:

l.i
<?php
$num = 3;
switch ($num)
{
case 1: da
ka
echo “One”;
break;
case 2:
vi

echo “Two”;
break;
al

case 3:
echo “Three”;
.k

break;
case 4:
w

echo “Four”;
break;
w

case 5:
echo “Five”;
w

break;
default:
echo “Number is not between 1 to 5.”;
break;
}
?>
OUTPUT:
 Three
RESULT:
 The expected output is achieved.

[OR]
Program: 2 [ CREATING NOTICE BOARD ]
QUESTION - 3

Program: 8
Write a PHP script to print 1 to 10 number in separate line using while loop.

AIM:
 To print the numbers from 1 to 10 on separate lines using a while loop.
PROCEDURE:
1. Open a new file in your text editor (Notepad).
2. Type the following PHP script.
3. Save the file in the following format “filename.php”. Let us take p4.php for an example.
4. Save the file p4.php in the file saving path - c:\wamp64\www\
5. Make sure Apache is started in Wampserver.
6. Go to the browser and type:-http://localhost/p4.php In your web browser, you should see
the results of your script.

n
PHP SCRIPT:

l.i
<?php
$number = 1;
while ($number <= 10)
{
echo “$number <br>”; da
ka
$number++;
}
?>
vi

OUTPUT:
1
al

2
3
.k

4
5
w

6
7
w

8
9
w

10

RESULT:
 The expected output is achieved.

[OR]

Program: 3 [ CREATING VISITING CARD ]

PREPARED BY..., B.MOHAMED YOUSUF M.C.A., B.Ed.., (PG ASST IN COMPUTER SCIENCE)
QUESTION - 4

Program: 9
Write a PHP script that calculates the sum and product of the numbers from 1 to 10 using for
loop.

AIM:
 To write a PHP script that calculates the sum and product of the numbers from 1 to 10
using for loop.
PROCEDURE:
1. Open a new file in your text editor (Notepad).
2. Type the following PHP script.
3. Save the file in the following format “filename.php”. Let us take p5.php for an example.
4. Save the file p5.php in the file saving path - c:\wamp64\www\
5. Make sure Apache is started in Wampserver.

n
6. Go to the browser and type:-http://localhost/p5.php In your web browser, you should see

l.i
the results of your script.
PHP SCRIPT:
<?php
$sum = 0;
$product = 1; da
ka
for ($i = 1; $i<= 10; $i++)
{
$sum += $i;
vi

$product *= $i;
}
al

echo “The sum of the numbers from 1 to 10 is: $sum <br>”;


echo “The product of the numbers from 1 to 10 is: $product <br>”;
.k

?>
OUTPUT:
w

The sum of the numbers from 1 to 10 is: 55


The product of the numbers from 1 to 10 is: 3628800
w

RESULT:
 The expected output is achieved.
w

[OR]

Program: 4 [ CREATING LABEL ]

PREPARED BY..., B.MOHAMED YOUSUF M.C.A., B.Ed.., (PG ASST IN COMPUTER SCIENCE)
QUESTION - 5

Program: 10
Write a PHP script that loops through an array of names, prints each name and its
length, and counts the total number of names using ‘foreach’.

AIM:
 To use a foreach loop to iterate through an array in PHP and access its elements.
PROCEDURE:
1. Open a new file in your text editor (Notepad).
2. Type the following PHP script.
3. Save the file in the following format “filename.php”. Let us take p6.php for an example.
4. Save the file p6.php in the file saving path - c:\wamp64\www\
5. Make sure Apache is started in Wampserver.

n
6. Go to the browser and type:-http://localhost/p6.php In your web browser, you should see

l.i
the results of your script.
PHP SCRIPT:
<?php

da
$names = array(‘Ram’, ‘Ravi’, ‘Kumar’, ‘Barath’, ‘Lavanya’);
foreach ($names as $name)
ka
{
echo “Name: $name<br>”;
echo “Length: “ . strlen($name) . “<br><br>”;
vi

}
$count = count($names);
al

echo “Total number of names: $count <br>”;


?>
.k

OUTPUT:
Name: Ram
w

Length: 3
w

Name: Ravi
Length: 4
w

Name: Kumar
Length: 5

Name: Barath
Length: 6

Name: Lavanya
Length: 7

Total number of names: 5


RESULT:
 The expected output is achieved.
[OR]
Program: 5
Write a PHP script to do the operations including addition, subtraction, multiplication,
division, modulus on 2 variables with values 10 and 5. The script should output the
results of each operation on a separate line.

AIM:
 To perform various arithmetic operations on two variables and output the results.
PROCEDURE:
1. Open a new file in your text editor (Notepad).
2. Type the following PHP script.
3. Save the file in the following format “filename.php”. Let us take pl.php for an example.
4. Save the file pl.php in the file saving path - c:\wamp64\www\
5. Make sure Apache is started in Wampserver.
6. Go to the browser and type:- http://localhost/pl.php In your web browser, you should see
the results of your script.

n
PHP SCRIPT:

l.i
<?php
$num1 = 10;
$num2 = 5;
$sum = $num1 + $num2;
$sub= $num1 - $num2; da
ka
$mul = $num1 * $num2;
$div = $num1 / $num2;
$mod = $num1 % $num2;
vi

echo “The sum of $num1 and $num2 is: $sum”;


echo “The subtraction of $num1 and $num2 is: $sub”;
al

echo “The multiplication of $num1 and $num2 is: $mul”;


echo “The division of $num1 and $num2 is: $div”;
.k

echo “The modulus of $num1 and $num2 is: $mod”;


?>
w

OUTPUT:
 The sum of 10 and 5 is: 15
w

 The subtraction of 10 and 5 is: 5


 The multiplication of 10 and 5 is: 50
w

 The division of 10 and 5 is: 2


 The modulus of 10 and 5 is: 0
RESULT:
 The expected output is achieved.

PREPARED BY..., B.MOHAMED YOUSUF M.C.A., B.Ed.., (PG ASST IN COMPUTER SCIENCE)

You might also like