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

Green University of Bangladesh: Final Examination Assignment

The document provides instructions for 4 programming assignments for a Web Programming course. It lists the course title and code, and provides a brief description of what is required for each of the 4 programming problems to be solved in PHP. The problems involve manipulating arrays, checking for prime numbers, comparing words in sentences, and rotating and summing arrays.

Uploaded by

tonmoy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views

Green University of Bangladesh: Final Examination Assignment

The document provides instructions for 4 programming assignments for a Web Programming course. It lists the course title and code, and provides a brief description of what is required for each of the 4 programming problems to be solved in PHP. The problems involve manipulating arrays, checking for prime numbers, comparing words in sentences, and rotating and summing arrays.

Uploaded by

tonmoy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

GREEN UNIVERSITY OF

BANGLADESH

Final Examination Assignment

COURSE TITEL: Web Programming

COURSE CODE: 301

Submitted To Submitted By
SAFIAL ISLAM AYON Name: MD Alamgir Hossen
ID: 181002049
Lecturer Section: 181_DB
Department of CSE Department of CSE
01. Take an array mixed of real and integer number.
Print them in ascending order along with their number
of occurrences. Write the PHP code.

PHP Code:

<?php

$number = array();
$n = readline("Number of input:
"); echo("Enter those
numbers: \n");
for($c = 0; $c< $n; $c++)
{
$num = readline();
$number[$c] = $num;
}

sort($number);
foreach((array_count_values($number)) as $x=>$y)
{
echo($x."->".$y." times\n");
}
?>

Output:
02. Print all the numbers between 2 to 999 in a
comma delimited format. Among those number
Prime numbers should be bolded. Write the PHP code.

PHP code:

<?php

function primeCheck($number){
for ($i = 2; $i <= sqrt($number);
$i++){ if ($number % $i == 0)
return false;
}
return true;
}

for($c = 2; $c<=999; $c++)


{
if (primeCheck($c))
{
echo "<b>".$c."</b>". ",";
}
else
{
echo($c.",");
}

}
?>
03.Read two arrays of words and find the length of the
largest common end (left or right). Write the PHP code.
PHP code:

<?php
$line1 = readline("first sentence:
");
$line2 = readline("second
sentence: ");
$words1 = explode(" ", $line1);
$words2 = explode(" ", $line2);
$left_match = 0;
$right_match = 0;
for($c = 0; $c < count($words1);
$c++)
{
if($words1[$c] != $words2[$c])
{
break;
}
$left_match++;
}
$words1 =
array_reverse($words1);
$words2 =
array_reverse($words2);
for($c = 0; $c < count($words1);
$c++)
{
if($words1[$c] != $words2[$c])
{
break;
}
$right_match++;
}
if($left_match > $right_match)
{
echo($left_match);
}
else
{
echo($right_match);
}
?>

Input/Output:
04. Write a PHP program to take a fixed array of n
integers (space separated on a single line) and an
integer k, rotate the array right k times and sum the
obtained arrays after each rotation

PHP code:

<?php
function rotate($array)
{
if(sizeof($array) == 1)
{
return $array;
}
$temp = $array[0];
for($c = 1; $c < sizeof($array); $c++)
{
$temp1 = $array[$c];
$array[$c] = $temp;
$temp = $temp1;
}
$array[0] = $temp;
return $array;
}
$numb = readline();
$numbers = explode(" ", $numb);
$n_r =readline();
$sum = array();
for($c = 0; $c < sizeof($numbers); $c++)
{
$sum[$c] = 0;
}
for($c = 0; $c< $n_r; $c++)
{
$rot = rotate($numbers);
$numbers = $rot;
for($d = 0; $d< sizeof($numbers) ; $d++)
{
$sum[$d] = $sum[$d] + $rot[$d];

}
foreach($sum as $num)
{
echo($num." ");
}
Sample Input:/Output

You might also like