Algorithm Project
Algorithm Project
University of Calcutta
Semester: 4rd
Subject: CMSA
CU Roll No: 213111–21-0050
CU Registration No: 111-1111-0143-21
Paper Code: CC-8 Practical
INDEX
DATE: Page |2
Q.1 write a php script to calculate the factorial of a given number using a function?
Code:
DATE: Page |3
<?php
function factorial($num) {
if ($num == 0 || $num == 1) {
return 1;
} else {
$result = factorial($number);
?>
Output:
Q.2 build a php script that generates a random quote from an array and displays it?
Code:
<?php
$quotes = array(
"Quote 1",
"Quote 2",
"Quote 3"
);
$randomIndex = array_rand($quotes);
$randomQuote = $quotes[$randomIndex];
echo $randomQuote;
?>
Output:
DATE: Page |4
Input:
<?php
function isPalindrome($str) {
if (isPalindrome($string)) {
} else {
?>
Output:
Q.4 write a php program to find the maximum and minimum values in an array of numbers?
Input:
<?php
function findMinMax($arr) {
$min = min($arr);
$max = max($arr);
$result = findMinMax($numbers);
?>
Output: