Green University of Bangladesh: Department of Computer Science & Engineering

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Mohammad Shahjalal 181002079

GREEN UNIVERSITY OF BANGLADESH


Department of Computer Science & Engineering
(ASSIGNMENT - 3)
COURSE TITEL: Web Programming

COURSE CODE: 301

Date of performance : 21 – 05 – 2020

Date of submission : 26 – 05 – 2020

Submitted To

SAFIAL ISLAM AYON


Lecturer

Department of CSE

Submitted By

Axdsft fttgf
ID: 181002078
Section: 181_DA
Department of CSE
Mohammad Shahjalal 181002079

Question:
Assignment 3:
SET- I
01. Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence. In a Fibonacci
sequence the sum of two successive terms gives the third term.
Following are the first few terms of the Fibonacci sequence: 1 1 2 3 5 8 13 21 34 55 89...
02. Write a program that asks the user for two positive integer number N1 and N2. Find the GCD
(Greatest Common Divisor) of N1and N2.
03. Write a program to check whether a triangle is valid or not, when the three angles of the triangle are
given. A triangle is valid if the sum of all the three angles is equal to 180 degrees.

Answer
Que-01. Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence. In a Fibonacci
sequence the sum of two successive terms gives the third term.
Answer-1:

PHP CODE:
<?php

$num = 25;
echo "<h3>Fibonacci series using recursive function:</h3>";
echo "\n";

function fib($num)
{
if($num == 0){
return 0;
}
else if( $num == 1){
return 1;
}
Mohammad Shahjalal 181002079

else {
return (fib($num-1) + fib($num-2));
}
}

for ($i = 0; $i < $num; $i++){


echo fib($i);
echo " ";
}

OUTPUT

Que-02. Write a program that asks the user for two positive integer number N1 and N2. Find the GCD
(Greatest Common Divisor) of N1and N2.
Answer-2:

PHP CODE:
<html>

<body>
<form action="" method="post" >
<br><br><h1>Assignment 3<br>Mohammad Shahjalal<br>181002079</h1><br>
Enter First Value:
<input type="string" name="no1"><br><br>
Mohammad Shahjalal 181002079

Enter Second Value:


<input type="string" name="no2"><br><br>
<input type="submit" name="submit" value=" GCD " ><br><br>

</form>
</body>
</html>
<?php

function gcd($a, $b)


{
if($b==0)
return $a ;

return gcd( $b , $a % $b ) ;
}
if($_POST)
{
$a=$_POST['no1'];
$b=$_POST['no2'];
echo "GCD of $a and $b is ", gcd($a , $b) ;
}
?>
Mohammad Shahjalal 181002079
Mohammad Shahjalal 181002079
Mohammad Shahjalal 181002079

OUTPUT:

You might also like