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

Ost Perl, PHP PGMS

The document contains multiple programming exercises demonstrating basic functionalities in Perl and PHP. It includes palindrome checking, array sorting, finding the largest and smallest numbers in an array, and printing the days of the week based on user input. Each exercise provides sample input and output, confirming successful execution and verification of the programs.

Uploaded by

Migavel D
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)
5 views4 pages

Ost Perl, PHP PGMS

The document contains multiple programming exercises demonstrating basic functionalities in Perl and PHP. It includes palindrome checking, array sorting, finding the largest and smallest numbers in an array, and printing the days of the week based on user input. Each exercise provides sample input and output, confirming successful execution and verification of the programs.

Uploaded by

Migavel D
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/ 4

EX.NO.

:2A Palindrome Checking using PERL


PROGRAM:

print "Enter a number : ";


$s1=<stdin>;
chomp $s1;
$s2=reverse($s1);
print "The reversed number is : ", $s2;
if ($s1 == $s2)
{
print "\nThe given number is a Palindrome ";
}
else
{
print "\nThe given number is not a Palindrome";
}

SAMPLE INPUT AND OUTPUT:

Enter a number : 56765


The reversed number is : 56765
The given number is a Palindrome

Enter a number : 12345


The reversed number is : 54321
The given number is not a Palindrome

RESULT:
The above program is executed successfully and the output is verified.

EX.NO.:2B Sorting an Array using PERL


PROGRAM:

#Sorting an Array using PERL


print "Enter the array size : ";
$size= <stdin>;
chomp $size;
print "\nEnter the array elements : \n";
for (1 .. $size)
{
$item=<stdin>;
push @arr,$item;
}
print "\nThe array in ascending order is : \n", sort {$a cmp $b} @arr;
print "\nThe array in descending order is : \n", sort {$b cmp $a} @arr;

SAMPLE INPUT AND OUTPUT:


Enter the array size : 7
Enter the array elements :
12
17
42
36
82
77
61
The array in ascending order is :
12
17
36
42
61
77
82

The array in descending order is :


82
77
61
42
36
17
12

RESULT:
The above program is executed successfully and the output is verified.
EX.NO.:3A Finding the Largest and Smallest numbers in an array
using PHP

PROGRAM:

<?php
$arr= explode(' ', readline("Enter an array of values in a single line: "));
print_r($arr);
$max=max($arr);
$min=min($arr);
echo "The Largest number of the array is: ",$max,"\n" ;
echo " The Smallest number of the array is: ",$min;
?>

SAMPLE INPUT AND OUTPUT:


Enter an array of values in a single line: 63 12 79 94 81
Array
(
[0] => 63
[1] => 12
[2] => 79
[3] => 94
[4] => 81
)
The Largest number of the array is: 94
The Smallest number of the array is: 12

RESULT:
The above program is executed successfully and the output is verified.

EX.NO.:3B Print the days of the week using PHP

PROGRAM:
// Print the days of the week using PHP
<?php
$day=readline("Enter a number for a day : ");
switch ($day)
{
case 1:
echo "Sunday";
break;
case 2:
echo "Monday";
break;
case 3:
echo "Tuesday";
break;
case 4:
echo "Wednesday";
break;
case 5:
echo "Thursday";
break;
case 6:
echo "Friday";
break;
case 7:
echo "Saturday";
break;
default:
echo "Enter a number between 1 and 7";
}
?>

SAMPLE INPUT AND OUTPUT:


Enter a number for a day : 4
Wednesday

Enter a number for a day : 8


Enter a number between 1 and 7

RESULT:
The above program is executed successfully and the output is verified.

You might also like