0% found this document useful (0 votes)
55 views67 pages

Group 3 Algorithm

The document describes 4 algorithms: 1. Finds the biggest of 3 positive numbers by comparing the numbers and outputting the largest 2. Converts Celsius temperatures from 20-100 degrees to Fahrenheit in 10 degree increments 3. Calculates the factorial of a given integer by multiplying all integers from 1 to the given number 4. Will calculate the sum of a series from a given x value and n terms

Uploaded by

Reymart Selverio
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)
55 views67 pages

Group 3 Algorithm

The document describes 4 algorithms: 1. Finds the biggest of 3 positive numbers by comparing the numbers and outputting the largest 2. Converts Celsius temperatures from 20-100 degrees to Fahrenheit in 10 degree increments 3. Calculates the factorial of a given integer by multiplying all integers from 1 to the given number 4. Will calculate the sum of a series from a given x value and n terms

Uploaded by

Reymart Selverio
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/ 67

Algorithm 1: To find biggest of the three unequal positive numbers

Algorithm 1 PHP Implementation


//Enter Number
Algorithm: Find biggest of 3 positive integers <form method="post">
<input type="number" min=0
Input: 3 integers name="1stnumber">
Output: biggest among inputs <input type="number" min=0
name="2ndnumber">
Step 1: Read $num1, $num2, $num3. <input type="number" min=0
Step 2: if num1 > $num2 && $num1 > $num3,go name="3rdnumber"><br>
to step 4, go to step 5 ,else go to step 3. <input type="submit" name="btnSubmit">
Step 3: if $num2 > $num1 && $num2 > $num3,go </form>
to step 6 , else go to step 4. //Use php
Step 4: if $num3 > $num2 && $num3 > $num1 go <?php
to step 7, else go to step 2. if(isset($_POST['btnSubmit'])){
Step 5: display $num1, then go to step 8. //Declare variables
Step 6: display $num2, then go to step 8. $num1=$_POST['1stnumber'];
Step 7: display $num3, then go to step 8. $num2=$_POST['2ndnumber'];
Step 8: stop. $num3=$_POST['3rdnumber'];
//Compare output and print Output
if($num1 > $num2 && $num1 > $num3){
echo $num1.",
".$num2.", ".$num3, " (1st is the biggest
number)";
}else if($num2 > $num1 &&
$num2 > $num3){
echo $num1.",
".$num2.", ".$num3, " (2nd is the biggest
number)";
}else if($num3 > $num2 &&
$num3 > $num1){
echo $num1.",
".$num2.", ".$num3, " (3rd is the biggest
number)";
}
}
?
Output:
Enter 1st number:2
Enter 2nd number:4
Enter 3rd number:6
6

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 1
FLOWCHART No.1
To find the biggest of the three unequal positive numbers

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 2
Algorithm 2: To convert and display 20 to 100 °C range values into °F, 10+ increment in
each step.
To convert temperature from degree Celsius to Fahrenheit scale, below formula is used.

°F = 1.8°C + 32

Algorithm 2 PHP Implementation


//Input Celsius
Algorithm: Converting °C to °F. <form method=”post”>
<input type="number" name="1stdegree"><br>
Input: --- <input type="submit" name="btnConvert">
Output: 20-100°C values in °F </form>

Step 1: Input C //Use php


Step 2: Read C <?php
Step 3: C = 20. if(isset($_POST['btnConvert'])){
Step 4: if c>100 go to step 8, else continue. //Declare variable $c and $n.
Step 5: F = 1.8*C + 32. $c=20;
Step 6: C = C + 10. $n=$_POST['1stdegree'];
Step 7: display F.
Step 8: stop. //Calculate and print output.
do{
$f=1.8 * $n + 32;
$c=$c + 10;
}while($c <= 100);
echo “input : ”,$n,”°C”;
echo “output : ”,$f,"°F";
}
?>
Output:
Input Celsius: 35
Output: 95 Fahrenheit.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 3
FLOWCHART No.2
To convert and display 20 to 100 °C range values into °F, 10+ increment in each
step.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 4
Algorithm 3: To find factorial of given integer number.
Algorithm 3 PHP Implementation
//Input Integer
Algorithm: Find factorial number of given N. <form method=”post”>
<input type="number" min=0
Input: integer N. name="one"><br>
Output: factorial of N. <input type="submit" name="btnfind">
</form>
Step 1: Input N.
Step 2: F=1, I=1. //Use php
Step 3: I = I + 1. <?php
Step 4: F = F * I. if(isset($_POST['btnfind'])){
Step 5: If f<=N go to step 3, else continue.
Step 6: Display F. //Declare variable $x and $f.
Step 7: Stop $x=$_POST['one'];
$f=1;
echo "input = ",$x,"<br>";
//Calculate and print output.
for($i=1; $i<= $x; $i++){
$f = $f * $i;
}
echo "output = ",$f;
}
?>
Output:
Input Number: 4
Number Factorial: 24

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 5
FLOWCHART No.3
To find factorial of given integer number.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 6
Algorithm 4: To find sum of the series from given x and n value.
𝟏 + 𝐱 𝟏 + 𝐱 𝟐 + 𝐱 𝟑 +. . . . . + 𝐱 𝐧 .

Algorithm 4 PHP Implementation


//Enter number and exp
Algorithm: Find sum of given number and its sum. <form method="POST">
<table border=1 bgcolor=pink>
Input: Input Integer n1 and x1 <tr>
Output: Sum of given series <td>ENTER NUMBER</td>
<td><input type="number"
Step 1: Read $n1 and $n2. name="num1" ></td><br>
Step 2: Print or echo "Input </tr>
:",$n1,"^",$x1,"<br>"; continue <td>ENTER Exp</td>
Step 3: for($c=1; $c<=$x1; $c++), continue <td><input type="number"
Step 4: $mul = $mul * $n1; name="exp1" ></td><br>
Step 5: $sum = $sum+$mul; </tr>
Step 6: Display $sum <tr>
Step 7: Stop. <td colspan="2"><input
type="submit" name="btnsubmit"
value="submit"></td><br>
</tr>
</table>
</form>
</body>
</html>
//Use php
<?php
//Declare $n1 and $x1
$n1='';
$x1='';

if(isset($_POST['btnsubmit'])){
$n1 = $_POST['num1'];
$x1 = $_POST['exp1'];
//Calculate and print output
echo "Input :",$n1,"^",$x1,"<br>";
$mul=1;
$sum=0;
for($c=1; $c<=$x1; $c++){
$mul = $mul * $n1;
$sum = $sum+$mul;

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 7
echo "Value : ",$mul,"<br>";
echo "Sum : ",$sum;
}
?>
Output:
Input Number: 4
Input Exp: 3
Output:
Input :4^3
Value : 64
Sum : 84

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 8
FLOWCHART No.4
To find sum of the series from given x and n value.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 9
Algorithm 5: To print entered currency into its part, say $12.62 is dollar 12 and 62
cents.

Algorithm 5 PHP Implementation


//Input Integer
Algorithm: Find parts of entered currency value. <form method=”post”>
<input type="integer" name="num4">
Input: Currency <input type="submit" name="btnval">
Output: Entered currency into its part </form>

Step 1: Read Input. //Use php


Step 2: wholeNum = intval(Input). <?php
Step 3: Fraction = (Input - int(Input))*100. if(isset($_POST['btnval'])){
Step 4: print currency is made of dollars and //Declare $num.
cents. //Calculate and print output.
Step 5:Stop. $num = $_POST['num4'];
$n=number_format($num,2);
$dec = ($num - intval($n))*100;
echo "dollars ",intval($n)," and ",$dec,"
cents" ;
}
?>
Output:
Input Currency: 20.25
Output: Currency is made of 20 dollars and 25
cents.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 10
FLOWCHART No.5
To print entered currency into its part, say $12.62 is dollar 12 and 62 cents.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 11
Algorithm 6: To find the volume of pyramid, when it’s base and height are given
Algorithm 6 PHP Implementation
//Input Integer
Algorithm: Find volume of pyramid <html>
<head>
Input: Base, Height. <title>Algorithm #6</title>
Output: Volume of pyramid </head>
<body>
<?php
//Initialize
Step 1: Read Base & Height $l='';
Step 2: $V= ($l * $h) / 3; $h='';
Step 3: Print Volume. $res='';
Step 4: Stop. //V=lwh/3;
//declare variable
if(isset($_POST['btnsubmit'])){
$l=$_POST['l'];
$h=$_POST['h'];
$V= ($l * $h) / 3;
$res = $V;
}?>
//read input
<form method="POST">
<table border=1 bgcolor=pink>
<tr>
<td>ENTER Base Lenght:</td>
//calculate print output
<td><input type="number" name="l"
value="<?php echo $l;?>"></td><br>
</tr>
<tr>
<td>ENTER Pyramid Height:</td>
<td><input type="number" name="h"
value="<?php echo $h;?>"></td><br>
</tr>
<tr>
<td>VOLUME:</td>
<td><input type="number" readonly
value="<?php echo $res;?>"></td><br>
</tr>

//Print
<tr>
<td colspan="2"><input type="submit"
name="btnsubmit" value="test"></td><br>
</tr>
</table>

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 12
</form>
</body>
</html>
Output:
Enter Base & Height. 4.0 9.0
Volume = 48.00

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 13
FLOWCHART No.6
To find the volume of pyramid, when it’s base and height are given.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 14
Algorithm 7: To print given number in reverse order and its digits total.
Algorithm 7 PHP Implementation
//Input Integer
Algorithm: Print given number in reverse order <html>
and total of its digits. <head>
<title>reverse</title>
Input: Integer number ln </head>
Output: Reverse on ln, total of digits. <body bgcolor="lightgreen" >
<form method="POST">
<table bgcolor="lightblue" >
Step 1: Read $ln; <td>ENTER NUMBERS</td>
Step 2: $rem=$ln%10; <tr>
Step 3: Print digit. //declare variable
Step 4: Total = digit, length = length – 1. <td>ENTER NUMBERS</td>
Step 5: $ln=$ln/10; <td><input type="number" name="num"
Step 6: digit = $ln mod 10 value="<?php echo $ln;?>"><br></td>
Step 7: Print digit. </tr>
Step 8: Total = total + digit, length = length – 1. <tr>
Step 9: for ($i =0; $i<=strlen($ln);$i++) . <td colspan="2"><input type="submit"
Step 10: stop name="btnreverse" value="REVERSE" ></td>
</tr>
</table>
</form>
</body>
</html>
//Use php
<?php
if(isset($_POST['btnreverse'])){
$ln = $_POST['num'];
//echo"Input = ",$ln,"<br>";
//Calculate
$rev = strrev($ln);
$n = $_POST['num'];
echo "Reverse = ",$rev,"<br>";
$sum=0; $rem=0;
for ($i =0; $i<=strlen($ln);$i++)
{
$rem=$ln%10;
$sum = $sum + $rem;
$ln=$ln/10;
} echo "Total of Input Numbers: = ", $sum;}
?>
Output:
Enter length of number & number.
1234
4321 Total=10

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 15
FLOWCHART No.7
To print given number in reverse order and its digits total.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 16
Algorithm 8: To print given month’s total days.
Algorithm 8 PHP Implementation
//Input Integer
Algorithm: Print given moth’s total days. <html>
<head>
Input: Integer number N <title>"Printing Given Month's Total Days"</title>
Output: N’s total days. </head>
<body>
<form method="POST">
Step 1: Read month number $num, Enter a Number<br>
Step 2: if $num is case 1 or case 3 or case 5 or <input type="number" name="num"><br>
case 7 or case 8 or case 10 or case 12 <input type="submit" name="btntest"
Then continue, else go to step 4. value="Result"><br>
Step 3: echo "Month has 31 days", then go to </form>
step 8. </body>
Step 4: if case 4 or case 6 or case 9 or case 11 </html>
then continue else go to step 6 //Use php
Step 5: echo "Month has 28/29 days"; <?php
Step 6: if $num is 2 then continue, else go to step //input
8 if(isset($_POST['btntest'])){
Step 7: echo "Month has 28/29 days". $num=$_POST['num'];
Step 8: Stop. //Calculate, print outpu
switch ($num) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
echo "Month has 31 days";
break;
case 4:
case 6:
case 9:
case 11:
echo "Month has 30 days";
break;
default:
echo "Month has 28/29 days";}
}
?>
Output:
Enter month number: 4
Output: Month has 30 days

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 17
FLOWCHART No.8
To print given month’s total days.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 18
Algorithm 9: To create simple calculator for + & - operations
Algorithm 9 PHP Implementation
//Input Integer
Algorithm: Create simple calculator <html>
<head>
Input: operation & numbers. <title>"Simple Calcu"</title>
Output: output of operation. </head>
<body>
<form method="POST">
Step 1: Read two integers $num1, $num2. Enter 2 numbers<br>
Step 2: Press 1 to Add. <input type="number" name="n1"><br>
Press 2 to Subtract. <input type="number" name="n2"><br>
Press 3 to Exit. <br>
Press 1 to Add<br>
Step 3: if($res==1) go to step 4 Press 2 to Subtract<br>
if($res==2) go to step 5 Press 3 to Exit<br>
Else = go to step 6 <input type="number" name="response"><br>
Else go to step 2 <br>
<input type="submit" name="btntest"
Step 4: echo $num1+$num2. Go step 1. value="Result"><br>
Step 5: echo $num1-$num2. Go step 2 </form>
Step 6: stop. </body>
</html>
//Use php
<?php
if(isset($_POST['btntest'])){
$num1=$_POST['n1'];
$num2=$_POST['n2'];
$res=$_POST['response'];
//Calculate
if($res==1){
echo $num1+$num2;}
else if($res==2){
echo $num1-$num2;}
else{
die();}
}
?>
Output:
Enter 2 integers. 2 4
Press 1 for Add
Press 2 for Subtract
Press 3 for exit
1
Addition = 6

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 19
FLOWCHART No.9
To create simple calculator for + & - operations

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 20
Algorithm 10: To find first N natural number’s sum and average.
Algorithm 10 PHP Implementation
//Input Integer
Algorithm: Find natural numbers sum and <html>
average. <head>
<title>"Fibnacci Sequence"</title>
Input: Natural Number Num. </head>
Output: Sum and average of N series. <body>
<form method="POST">
Enter a Number<br>
Step 1: Read $num <input type="number" name="num"><br>
Step 2: $f0 = 0, $f1 = 1, c=0 <input type="submit" name="btntest"
Step 3: if ($c < $num) continue else go to value="Result"><br>
step 6. </form>
Step 4: Sum $f2 = $f1 + $f0; </body>
Step 5: $c = $c + 1; </html>
Step 6: Average $c = $c + 1; continue else //Use php
go to step 5. <?php
Step 7: Print sum & Average //input
Step 8: stop if(isset($_POST['btntest'])){
function Fibonacci($num){
$f0 = 0;
$f1 = 1;
$c = 0;
//calculate print output
while ($c < $num){
echo '<br>'.$c." - ".$f0;
$f2 = $f1 + $f0;
$f0 = $f1;
$f1 = $f2;
$c = $c + 1;}
}
$num=$_POST['num'];
Fibonacci($num);
}
?>

Output:
Enter N.5
Sum=15.00,Avg=3.00

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 21
FLOWCHART No.10
To find first N natural number’s sum and average.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 22
Algorithm 11: To reverse given number.
Algorithm 11 PHP Implementation

Algorithm: Reverse given number. <html>


<head>
Input: N. <title>Algorithm #11</title>
Output: Reverse of N. </head>
<body>
Step 1: Read N. //Enter Numbers.
Step 2: If (N > 0) continue else go to step 3. <form method="POST">
Step 3: Print Rev. <table border=1 bgcolor=pink>
Step 4: Stop <tr>
<td>ENTER NUMBERS</td>
<td><input type="number"
name="num"><br></td>
</tr>
tr>
<td colspan="2"><input type="submit"
name="btnsubmit" value="submit"></td><br>
</tr>
</table>
</form>
</body>
</html>

//Use php
<?php
//Declare variable $n.
$n='';
if(isset($_POST['btnsubmit'])){
$n=$_POST['num'];
//Calcuate and print output.
echo 'Numbers: '.$n.'<br>';
$rev=strrev($n);
echo '<br> Reverse: '.$rev;

?>
Output:
Enter Numbers: 1231
Output: 1321

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 23
FLOWCHART No.11
To reverse a given number.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 24
Algorithm 12: To print Fibonacci series for given numbers
Algorithm 12 PHP Implementation

Algorithm: Print Fibonacci series for given <html>


numbers. <head>
<title>Algorithm #12</title>
Input: N. </head>
Output: Fibonacci series of N. //Input N.
<body>
Step 1: Read N. <form method="POST">
Step 2: F0 = 1, F1 = 1. <table border=1 bgcolor=pink>
Step 3: If (N > 0) continue else go to step 5. <tr>
Step 4: Print 0 - 1 <td>ENTER NUMBER</td>
Step 5: If (N > 1) continue else go to step 7. <td><input type="number" name="n"
Step 6: Print 1 - 1 value="<?php echo $n;?>"><br></td>
Step 7: I -2. </tr>
Step 8: F2 = F0 + F1. <tr>
Step 9: Print I – F2. <td
Step 10: F0 = 1, F1 = 1. colspan="2"><input type="submit"
Step 11: I – I + 1. name="btnsubmit" value="series"></td><br>
Step 12: If (I < N) go to step 8 else continue. </tr>
Step 13: Stop. </table>
</form>
</body>
</html>
<?php
//Declare $n, $f0, $f1,$f2.
$n='';
$f0='';
$f1='';
$f2='';

if(isset($_POST['btnsubmit'])){
$f0=1; $f1=1;
$n=$_POST['n'];
echo "Input Number: = ",$n,"<br><br>";
echo "Series of Numbers:","<br>";
//Calculate and print output
if($n>0){ echo "0-1",".<br>";}
if($n>1){ echo "1-1",".<br>";}

for($i=2;$i<=$n;$i++){
$f2 = $f0+$f1;
echo $i,"-",$f2,".<br>";
$f0=$f1; $f1=$f2;
}
}

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 25
?>
Output
Enter Number: 4
Output:
Series of Number:
0-1
1-1
2-2
3-3
4-5

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 26
FLOWCHART No.12
To print the Fibonacci series for given numbers

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 27
Algorithm 13: To print table of numbers from 5 to 1 along N+5.
Algorithm 13 PHP Implementation

Algorithm: Print table of numbers from 5 to 1 <html>


along N+5. <head>
<title>Algorithm #13</title>
Input: --. </head>
Output: table of N+5. <body>
//Print N-N+5.
Step 1: Print N – N-5. <div class="col-md-4">
Step 2: I = 5. <h4 class="alert">N N-5</h4>
Step 3: If ( I > 0) continue else go to step 6. //Use php
Step 4: Print I – I + 5. <?php
Step 5: I = I – 1. //Print Output
Step 6: Go to step 2. for($i=5; $i>0; $i--){
Step 7: Stop. $n=$i+5;
echo $i," - ",$n,"<br>";
}
?>
<div>
</body>
</html>

Output:
N N+5
5 - 10
4-9
3-8
2-7
1-6

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 28
FLOWCHART No.13
To print table of numbers from 5 to 1 along N+5.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 29
Algorithm 14: To print triangle of natural integers made of given number of lines
height.
Algorithm 14 PHP Implementation

Algorithm: Print triangle made of given numbers <html>


of lines height. <head>
<title>Algorithm #14</title>
Input: L. </head>
Output: Triangle of L lines.
<body>
Step 1: Read N.
Step 2: N = 1. I = 1. <form method="POST">
Step 3: Print N. <table border=1 bgcolor=pink>
Step 4: N = N+1. I= I + 1. <tr>
Step 5: Go to step 3 <td>ENTER NUMBER</td>
Step 6: stop. <td><input type="number"
name="num" ></td><br>
</tr>
<tr>
<td colspan="2"><input
type="submit" name="btnsubmit"
value="submit"></td><br>
</tr>
</table>
</form>
</body>
</html>

<?php
if(isset($_POST['btnsubmit'])){
$n=$_POST['num'];
$cnt=0;
for($c=1;$c<=$n;$c++){
for($i=1;$i<=$c;$i++){
$cnt=$cnt+1; echo $cnt;
echo ' '; }echo'<br>';}
}
?>
Output:
Enter Number: 4
Output:
1
23
456
7 8 9 10

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 30
FLOWCHART No.14
To print triangle of natural integers made of given number of lines height.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 31
Algorithm 15: To determine roots of quadratic equations from given coefficients.
Algorithm 15 PHP Implementation

Algorithm: Determine roots of Q-equations. <html>


<head>
Input: Coefficients A, B, C. <title>"Finding Roots"</title>
Output: Type of equation. </head>
//Enter Coefficient A, B and C
Step 1: Read A, B, C. <body>
Step 2: Disc = B2 - 4AC. <form method="POST">
Step 3: If (Disc = 0) continue else go to 7. Enter Coefficient A<br>
Step 4: X1= B/2A, X2= -B/2A. <input type="number" name="num1"><br>
Step 5: Print roots are real & unequal. Enter Coefficient B<br>
Step 6: Print X1,X2, go to step 15 <input type="number" name="num2"><br>
Step 7: If (Disc > 0) continue else go to step 11. Enter Coefficient C<br>
Step 8: X1= (-B+Sqr(Disc)/2A, <input type="number" name="num3"><br>
X2= (-B-Sqr(Disc)/2A.
Step 9: Print roots are real & unequal. <input type="submit" name="btntest"
Step 10: Print X1,X2, go to step 15. value="Result"><br>
Step 11: Print roots are complex. </form>
Step 12: Print D = |D| </body>
Step 13: Real Part = -B/2A, </html>
Imaginary Part = sqr(Disc)/2A. //Use php
Step 14: Print X1= Real Part+ i.Imaginary Part, <?php
X2= Real Part- i.Imaginary Part. if(isset($_POST['btntest'])){
Step 15: stop. //Declare $a, $b, and $c.
$a=$_POST['num1'];
$b=$_POST['num2'];
$c=$_POST['num3'];

//Calculate and Print output.


$disc=(($b*$b)-4*$a*$c);

$x1=$b/(2*$a);
$x2=-$b/(2*$a);

$rPart=-$b/(2*$a);
$iPart=$b/(2*$a);

if($disc==0){
echo "Roots=Real N Equal. ";
echo $x1.", ".$x2;
}

else if($disc>0){
echo "Roots=Real N Unequal ";
$x1=((-$b+sqrt($disc))/(2*$a));

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 32
$x2=((-$b+sqrt($disc))/(2*$a));
echo $x1.", ".$x2;
}
else{
echo "Roots=Complex. ";
$rPart=-$b/(2*$a);

$x2=sqrt(Abs($disc))/(2*$a);
echo $x1="+i ".$iPart.", ". $x2="-i ".$rPart;
}
}
?>

Output:
Enter Coefficient A, B and C
Output: Roots=Real N Equal. 1, -1

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 33
FLOWCHART No.15
To determine roots of quadratic equations from given coefficients.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 34
Algorithm 16: To determine given triangle’s type and print its area.
Algorithm 16 PHP Implementation

Algorithm: Determine type & area of given <html>


triangle <head>
<title>"Finding the Type of
Input: 3 sides of triangle Triangle and its Area"</title>
Output: type and area. </head>
//Enter Side A, Side B and Side C.
Step 1: Read A, B, C. <body>
Step 2: S= (A+B+C)/2. <form method="POST">
Step 3: Area= Sqrt(S(S-A)(S-B)(S-C)). Enter Side A<br>
<input type="number" name="num1"><br>
Step 4: If (A=B)&(B=C) continue else go to step 6.
Step 5: Print Triangle=Equilateral. Go to Step 12. Enter Side B<br>
<input type="number" name="num2"><br>
Step 6: If (A=B)or(B=C)or(C=A) continue else go to
step 8. Enter Side C<br>
Step 7: Print Triangle=Isosceles. Go to step 12. <input type="number" name="num3"><br>

Step 8: If (A!=B)or(B!=C)or(C!=A) continue else go <input type="submit" name="btntest"


to step 10. value="Result"><br>
Step 9: Print Triangle=Scalene. Go to step 12. </form>
</body>
Step 10: If (A2B2=C2)or(B2+C2=A2)or(C2+A2=B2) </html>
continue else go to step 12. //Use php
Step 11: Print Triangle=Right Angled. <?php
if(isset($_POST['btntest'])){
Step 12: Print Area. //Declare $a, $b, and $c.
Step 13: Stop. $a=$_POST['num1'];
$b=$_POST['num2'];
$c=$_POST['num3'];
//Calculate and print ountput.
$s=($a+$b+$c)/2;
$area=sqrt($s*($s-$a)*($s-$b)*($s-$c));

if (($a==$b)&&($b==$c)){
echo "Equilateral
Triangle---";
}
else if (($a==$b)||($b==$c)||($c==$a)){
echo "Isosceles Triangle---";
}

else if
(($a!=$b)||($b!=$c)||($c!=$a)){
echo "Scalene Triangle---";}

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 35
else if(

(($a*$a)+($b*$b)+($c*$c))||

(($b*$b)+($c*$c)+($a*$a))||

(($c*$c)+($a*$a)+($b*$b))
){
echo "Right
Angled Triangle---";
}

else{
echo "error";
}

echo $area. " sqr units";


}
?>
Output:
Input Side A, B an C:
A=4 B=4 C=4
Output: Equilateral Triangle 6.9282 sqr units

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 36
FLOWCHART No.16
To determine given triangle’s type and print its area.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 37
Algorithm 17: To print given 0 to 100 numbers in words.
Algorithm 17 PHP Implementation
//Enter Number
Algorithm: To print given numbers in words. <form method="post">
<table>
Input Number N. <tr>
Output: N words. <td>Enter Your Number</td>
<td><input type="text" name="num"></td>
Step 1: Read n. </tr>
Step 2: set cnt=0, continue
Step 3: if cnt < n, go to step 4. Else go to step 6. <tr>
Step 4: Print textbox nm[]. <td colspan="2">
Step 5: cnt = cnt+1, go to step 3. <input type="submit" value="Convert"
Step 6: Read textbox values num[]. name="convert"/>
Step 7: set cnt2 = 0 </td>
Step 8: if cnt2 < n </tr>
Step 9: if num[cnt2]>=1 && num[cnt2]<=19
Step 10: Call ones() function, else </table>
Step 11: if num[cnt2]>=20 && num[cnt2]<=99 </form>
Step 12: Call tens () function, else </body>
Step 13: if num[cnt2]==100 </html>
Step 14: Print one hundred, else <form method="POST">
Step 15: Print Number out of Range! //Use php
Step 16: Stop. <?php
if(isset($_POST['convert'])){
$n=$_POST['num'];
//Use for loop to print textbox.
for($cnt=0;$cnt<$n;$cnt++){
echo '<input type="number"
name="nm[]"><br>';
}
echo '<input type="submit"
value="Convert" name="sbmt"/>';
}

//Enter Number and print Output.


if(isset($_POST['sbmt'])){
$num=$_POST['nm'];

for($cnt=0;$cnt<count($num);$cnt++){

if($num[$cnt]>=1 &&
$num[$cnt]<=19){

ones($num[$cnt]);
echo
'<br>';

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 38
}else if ($num[$cnt]>=20
&& $num[$cnt]<=99){

tens($num[$cnt]);
echo '<br>';
}else if
($num[$cnt]==100){
echo 'one
hundred<br>';
}else{
echo'Number
Out of Range!<br>';
}
}
}
function ones($n){
if($n==1) echo 'one';
else if($n==2) echo 'two';
else if($n==3) echo 'three';
else if($n==4) echo 'four';
else if($n==5) echo 'five';
else if($n==6) echo 'six';
else if($n==7) echo 'seven';
else if($n==8) echo 'eight';
else if($n==9) echo 'nine';
else if($n==10) echo 'ten';
else if($n==11) echo 'eleven';
else if($n==12) echo 'twelve';
else if($n==13) echo 'thirteen';
else if($n==14) echo 'fourteen';
else if($n==15) echo 'fifteen';
else if($n==16) echo 'sixteen';
else if($n==17) echo 'seventeen';
else if($n==18) echo 'eighteen';
else if($n==19) echo 'nineteen';

}function tens($n){
$nm=floor($n/10);
$r=$n%10;

if($nm==2) echo 'twenty ';


else if($nm==3) echo 'thirty ';
else if($nm==4) echo 'fourty ';
else if($nm==5) echo 'fifty ';
else if($nm==6) echo 'sixty ';
else if($nm==7) echo 'seventy ';
else if($nm==8) echo 'eighty ';
else if($nm==9) echo 'ninety ';

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 39
ones($r);
}
?>
</form>

Output:
Enter Number: 4
Output :
Enter Numbers:
5 = five
102 = Number Out of Range!
3 = three
28 = twenty eight

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 40
FLOWCHART No.17
To print given 0 to 100 numbers in words.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 41
Algorithm 18: To find tax deduction at source from given salaries

Algorithm 18 PHP Implementation

Algorithm: to find tax deduction for given salary. //Create input type box
ENTER NUMBER:
Input: Salary
Output: Tax Deduction //Use php for the functionalities
<?php
Step 1: Read Income if(isset($_POST['btntest'])){
Step 2: $n=$_POST['num1']. //declare variable
Step 3: if($n<=18000), Continue $n=$_POST['num1'];
else go to step 5 if($n<=18000){
Step 4: Tax=0. $flag=1;
Step 5: else if($n<=25000),Continue ///Calculate, print/echo the output.
else go to step 7. }else if($n<=25000){
Step 6: $tax=($n-18000)*0.2. $flag=2;
Step 7: else if($n<=50000) }else if($n<=50000){
else go to step 9. $flag=3;
Step 8: $tax=($n-25000)*0.3+1400. }else if($n<=100000){
Step 9: else if($n<=50000) $flag=4;
else go to step 11. }else if($n>100000){
Step 10: $tax=($n-50000)*0.4+8900 $flag=5;
Step 11: else if($n<=100000) }else{
else go to step 13: $flag=0;
Step 12: $tax=($n-100000)*0.5+28900 }
Step 13: else if($n>100000)
else go to step 15. switch($flag){
Step 14: $tax=-1; case 1: $tax=0;
Step 15: else, echo $flag=0. break;
Step 16: stop. case 2: $tax=($n18000)*0.2;
break;
case 3: $tax=($n-25000)*0.3+1400;
break;
case 4: $tax=($n-50000)*0.4+8900;
break;
case 5: $tax=($n-100000)*0.5+28900;
break;
default: $tax=-1;
break;
}

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 42
echo "Income= ".$n."<br>"."Tax
Deduction= ".$tax;
}
?>
Output:
Enter Your Income: 18,500
Tax Deduction : 100

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 43
FLOWCHART No.18
To find tax deduction at source from given salaries

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 44
Algorithm 19: To find the GCD or HCF or given two non-zero numbers
Algorithm 19 PHP Implementation

Algorithm: To Find GCD of two numbers //Create input type box


ENTER NUMBER:
Input: Positive integers x, y
Output: GCD Number //Use php for the functionalities
<?php
Step 1: Read x, y //use $_POST to load the url.
Step 2: $x=$_POST['num1']. //use btntest that holds button.
$y=$_POST['num2']. if(isset($_POST['btntest'])){
Step 3: if ($x > $y), continue //declare variables
Step 4: $temp = $x, continue $x=$_POST['num1'];
Step 5: $x = $y, continue. $y=$_POST['num2'];
Step 6: $y = $temp,continue ///Calculate, print/echo the output.
Step 7: for($i = 1; $i < ($x+1); $i++), continue if ($x > $y) {
Step 8: if ($x%$i == 0 and $y%$i == 0),continue $temp = $x;
Step 9: $gcd = $i,continue $x = $y;
Step 10: echo "GCD of $x and $y is: $gcd". $y = $temp;
Step 11: stop. }

for($i = 1; $i < ($x+1); $i++) {


if ($x%$i == 0 and $y%$i == 0)
$gcd = $i;
}

echo "GCD of $x and $y is: $gcd";


}
?>
Output:
ENTER TWO NUMBERS:
64 84
GCD = 4

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 45
FLOWCHART No.19
To find the GCD or HCF or given two non-zero numbers

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 46
Algorithm 20: To find number of non-zero digits in given number.
Algorithm 20 PHP Implementation

Algorithm: To find number of non-zero digits. //Create input type box


ENTER NUMBER:
Input: 3 numbers
Output: Non-zero digits number. //Use php for the functionalities
<?php
Step 1: Read $nm.
Step 2: $nm=array(). $i=0. $res=’’. $nm=array();
Step 3: $nm=$_POST[‘num’]. $i=0;
Step 4: if($nm%10!=0) echo $i=$i+1. $res='';
Then continue //use $_POST to load the url.
Step 5: $nm = ($nm)/10; //use btntest that holds button.
Step 6: use while($nm>0). if(isset($_POST['btntest'])){
Step 7: echo res. $nm=$_POST['num'];
Step 8: stop.
//Calculate, print/echo the output.
do{
if($nm%10!=0)
$i=$i+1;
$nm = ($nm)/10;
}while($nm>0 );
$res = $i;
?>
Output:
ENTER NUMBER: 10043
NON-ZERO DIGITS: 3

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 47
FLOWCHART No.20
To find number of non-zero digits in given number.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 48
Algorithm 21: To find & compare calculated six(x) series value with standard sin(x),
where x values varies from 0-90 degrees in 10+step.
Algorithm 21 PHP Implementation
#define PI 3.1415
Algorithm: To find sin(x) value, where x = 0-90
degrees in 10+ step main()
{
Input: --
Output: sin(x) series values. //declare variables
Int Q,D,I;
Step 1: Q = 0. Float X,S,Sum,Term;
Step 2: If (Q<=9) continue,
Else go to step 15. //ask user input & store
Step 3: D = Q *10 Printf(
Step 4: Convert D from degree to radians. “X[Deg] std SIN(X) series SIN(X)”
X = (D*3.1415)/180. );
Step 5: Standard value, S = sin(x). //Calculate,print Output.
Step 6: Sum = X, Term=x, I=1 for(Q=0;Q<=9;Q++){
Step 7: If (Abs(Term)<0.001) continue, D= Q*10;
Else go to step 12. X= D*PI/180;
Step 8: I = I+2. S = SIN(X);
Step 9: Term=(-1*Term*Sqr(X))/(I(I-1)). Sum= X; Term= X; I=1;
Step 10: Sum = Sum+Term. do{
Step 11: Go to step 7. I= I+2;
Step 12: Print D [degree], S [sin(X)], Term=(-1*Term*Sqr(X))/(I(I-1)).
Sum[calculated sin(x) value]. Sum = Sum+Term;
Step 13: Q = Q+1. }while(Abs(Term)<0.001);
Step 14: Go to step 2.
Step 15: Stop. Print(%d %f %f.”,D,S,Sum);
}//end of for
}//end of main

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 49
Algorithm 22: To print binary equivalent of given decimal number
Algorithm 22 PHP Implementation

Algorithm: To find binary equivalent of given //Create input type box


decimal number ENTER DECIMAL NUMBER:

Input: Decimal Number //Use php for the functionalities


Output: Binary Number if(isset($_POST['btnsubmit']))
{
Step 1: Read dec. $n = $_POST['n'];
Step 2: dec = $_POST['n']. $num = $dec. $n1 = $num = $n;
$dec. $n1 = $n;
$binary. $i=0. $binary;
Step 3: $n > 0, Continue. $i = 0; //Count for binary array
Step 4: $binary[$i] = $dec% 2. Continue ///Calculate, print/echo the output.
Step 5: $dec = (int)($dec / 2). Continue do{
Step 6: $i++. Continue $n > 0;
Step 7: use while($dec>0).Continue $binary[$i] = $n % 2; //Remainder will stored
Step 8: for ($j = $i - 1; $j >= 0; $j--) in binary array
Step 9: print/echo $binary[$j]. $n = (int)($n / 2);
Step 10: stop. $i++; //Count increment
}while($n>0);
echo "The Decimal number is : ".$num ;
echo '<br>';
echo "The Equivalent Binary number is : ";
for ($j = $i - 1; $j >= 0; $j--)
echo $binary[$j];
}
Output:
ENTER DECIMAL: 12
OUTPUT: 1100

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 50
FLOWCHART No.22
To print binary equivalent of given decimal number

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 51
Algorithm 23: To print decimal equivalent of given binary number.
Algorithm 23 PHP Implementation

Algorithm: To find decimal equivalent of given //Create input type box


binary number. Enter a binary number:
Input: Binary number.
Output: Decimal number. //Use PHP for the functionalities
<?php
Step 1: Read bin. //Use $_POST to load the URL
$bin1=$_POST['bin1']; //Use btnsubmit that holds button
if(isset($_POST['btnsubmit'])){
Step 2: Declare variables //Declare variables
$bin1=''; $bin1=$_POST['bin1'];
$dec=0; $bin1='';
$i=1; $dec=0;
$res=''; $i=1;
$res='';
Step 3: do{ //Calculate and print the output
$dec= $dec + ($bin1 % 10)*$i;
$bin1=$bin1/10; do{
$i=$i*2; $dec= $dec + ($bin1 %
} continue 10)*$i;
Step 4: while($bin1 != 0); $bin1=$bin1/10;
$res= $dec; $i=$i*2;
} continue }while($bin1 != 0);
$res= $dec;
Step 5: echo $bin1; }

Step 6: Stop. echo $bin1;

Output:
Enter a Number: 1101
Decimal number: 13

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 52
FLOWCHART No.23
To print decimal equivalent of given binary number

Yes

No

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 53
Algorithm 24: To print shown format triangle with height of given number lines.
Algorithm 24 PHP Implementation
Algorithm: To print triangle made of 1 to 9 //Enter Number
numbers with <10 lines height <form method="POST">
<table border=1 bgcolor=pink>
Input: Height of triangle N. <tr>
Output: Triangle <td>ENTER NUMBER</td>
<td><input type="number"
Step 1: Read N. name="n" ></td><br>
Step 2: for($j=0; $j<$n; $j++), continue. </tr>
Step 3: for($i=1; $i<=($n-$j);$i++){ <tr>
echo" &nbsp"; continue. <td colspan="2"><input
Step 4: for($k=1; $k<=($j);$k++){ type="submit" name="btntri"
echo $k;} value="test"></td><br>
Step 5: Print/ echo $k; then go to step 8. </tr>
Step 6: for($l=1; $l<=($k);$k--){ </table>
echo $k;} </form>
Step 7: Go to step 5. </body>
Step 8:Stop </html>
//Use php
<?php
//Declare $n,$j,$i,$k,$l
$n='';
$j='';
$i='';
$k='';
$l='';
if(isset($_POST['btntri'])){
$n = $_POST['n'];
//Calculate and print Output
for($j=0; $j<$n; $j++){
for($i=1; $i<=($n-$j);$i++){
echo" &nbsp";}
for($k=1; $k<=($j);$k++){
echo $k;}
for($l=1; $l<=($k);$k--){
echo $k;}
echo"<br>";} }
?>
Output:
Enter Number: 4
Output:
1
121
12321
1234321

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 54
FLOWCHART No.24
To print shown format triangle with height of given number lines

No
Yes No

Yes No
Yes No

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 55
Algorithm 25: To print prime numbers from given non-zero positive number range
Algorithm 25 PHP Implementation
Algorithm: To print prime numbers from given
range. //Create input type box
Enter a number:
Input: num
Output: prime numbers //Use PHP for the functionalities
<?php
Step 1: Read number. //Use $_POST to load the URL
$numbrer1=$_POST['num']; //Use btnsubmit that holds button
if(isset($_POST['btnsubmit']))
Step 2: Declare variables //Declare variables
$bin1=''; $number = $_POST['num'];
$dec=0; $limit = $number;
$i=1; $init = 2;
$res=''; //Calculate
while(TRUE)
Step 3: do{
$dec= $dec + ($bin1 % 10)*$i; {
$bin1=$bin1/10; $div = 2;
$i=$i*2; if($init > $limit)
} conitinue {
break;
Step 4: while($bin1 != 0); }
$res= $dec; while(TRUE)
} continue {
if($div > sqrt($init))
Step 5: echo $bin1; {
echo $init." ";
Step 6: Stop.
break;
}
if($init % $div == 0)
{

break;
}
$div = $div + 1;
}
$init = $init + 1;
}
//Print the output
echo "Input number is: ".$number;
echo"<br>";
echo "The Prime Numbers are: ";
echo "<br>";
}

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 56
?>
Output:

Input number is: 15


The Prime Numbers are : 1 2 3 5 7 11 13

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 57
FLOWCHART No.25
To print prime numbers from given non-zero positive number
range

No Yes

No

Yes

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 58
Algorithm 26: To print given string in reverse order
PHP Implementation

Algorithm 26
Algorithm: To print given string in reverse order.
//Create input type boxes
Input: string. Enter the range number:
Output: reverse string. Enter the string:

Step 1: Declare and read variables //Use PHP for the functionalities
$n=$_POST['num1']; <?php
$w=$_POST['w1']; //Use $_POST to load the URL
//Use btntest that holds button
Step 2: $res=substr($w,0,$n); continue if(isset($_POST['btntest'])){
//Declare and Read Variables
Step 3: $rev=strrev($res); continue $n=$_POST['num1'];
$w=$_POST['w1'];
Step 4: echo $rev;
//Use substr function to get the length of the
Step 5: Stop. string
$res=substr($w,0,$n);

//Use strrev function to reverse the string


$rev=strrev($res);

//print output
echo $rev;
}
?>
Output:

Enter range number: 12


Enter the string: happy coding

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 59
FLOWCHART No.26
To print given string in reverse order

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 60
Algorithm 27: To arrange given 10 real numbers in ascending order and print their sum
Algorithm 27 PHP Implementation
Algorithm: To arrange 10 numbers in ascending <html>
order and print sum of all. <head>
<title>Algorithm #27</title>
Input: 10 real numbers </head>
Output: Ordered output, sum

Step 1: Use html as front end to create input <body>


boxes in array
<form method="POST">
Step 2: Use PHP as backend to process the input <table border=1 bgcolor=pink>
data <tr>
<td>ENTER NUMBER</td>
Step 3: Use $_POST to load the URL </tr>

Step 4: Use btntest that holds button <?php


for($c=0;$c<10;$c++){
echo'
Step 5: Declare and read variables <tr><td><input type="integer"
$nm=$_POST['num']; name="num[] " ></td></tr>';
}
?>
Step 6: for($c=0;$c<10;$c++){ <tr>
echo $nm[$c]; <td colspan="2"><input
echo ", "; type="submit" name="btnsubmit"
} continue value="test"></td><br>
</tr>
Step 3: sort($nm); continue </table>
</form>
Step 4: $arrlength = count($nm); continue </body>
</html>
Step 5: for($x = 0; $x < $arrlength; $x++) {
echo $nm[$x]; <?php
echo " , " ;
} $sum=0;
Step 6: echo "Sum of the Numbers = if(isset($_POST['btnsubmit'])){
".array_sum($nm)."<br>"; $nm=$_POST['num'];

Step 7: Stop. echo "The Input numbers are: ";

sort($nm);

$arrlength = count($nm);
echo"<br>";

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 61
for($x = 0; $x <
$arrlength; $x++) {
echo $nm[$x];
echo " , " ;
}
echo"<br>";
echo "Sum of the
Numbers = ".array_sum($nm)."<br>";
}
?>
Output:

Enter 10 numbers: 1 3 2 4 5 7 6 9 8 0

Ordered output: 1 2 3 4 5 6 7 8 9 0
Sum of the Numbers: 45

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 62
FLOWCHART No.27
To arrange given 10 real numbers in ascending order and print
their sum

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 63
Algorithm 28: To find two given matrices are compatible for multiplication , if yes print
product matrices.
Algorithm 28 PHP Implementation
Algorithm: To print product of 2 matrices. <?php
$c=0;
Input: Two matrices $r=0;
Output: product matrix $col=0;
$rw=0;
Step 1: Read columns and row of first matrix. if(isset($_POST['getval']) || isset($_POST['btntest'])){
Step 2: Read columns and row of second $c=$_POST['col'];
matrix. $r=$_POST['row'];
Step 3:Generate input matrices $col=$_POST['col2'];
Step 4: Read matrices values $rw=$_POST['row2'];
Step 5: Check matrices compatibility }
Step 6: Perform matrix operation. ?>
Step 7: Print matrix result. <form method="POST">
Step 8: stop. 1st matrix<br>
<input type="number" name="col" placeholder="COL"
value="<?=$c?>">
<input type="number" name="row"
placeholder="ROW" value="<?=$r?>"><br>

2nd matrix<br>
<input type="number" name="col2"
placeholder="COL" value="<?=$col?>">
<input type="number" name="row2"
placeholder="ROW" value="<?=$rw?>"><br>
<input type="submit" name="getval"
value="GENERATE MATRIX">
<input type="submit" name="btntest" value="TEST
MATRIX"><br>
<?php

if(isset($_POST['getval'])){
$c=$_POST['col'];
$r=$_POST['row'];
$col=$_POST['col2'];
$rw=$_POST['row2'];

echo'matrix 1<br>';
for($c1=0;$c1<$r;$c1++){
for($c2=0;$c2<$c;$c2++){
echo'
<input type="number"
name="num['.$c1.']['.$c2.']" style="width:50px">
';
}

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 64
echo'<br>';
}
echo'matrix 2<br>';

for($c1=0;$c1<$rw;$c1++){
for($c2=0;$c2<$col;$c2++){
echo'
<input type="number"
name="num2['.$c1.']['.$c2.']" style="width:50px">
';
}
echo'<br>';
}
}
?>
</form>
<?php
$num='';
$num2='';
if(isset($_POST['btntest'])){
$c=$_POST['col'];
$r=$_POST['row'];
$col=$_POST['col2'];
$rw=$_POST['row2'];
$num=$_POST['num'];
$num2=$_POST['num2'];
if($c==$rw){
echo'New Matrix<br>';
for($cn2=0;$cn2<$r;$cn2++){

for($cn3=0;$cn3<$col;$cn3++){

$sum=0;
for($cn=0;$cn<$c;$cn++){

$pro=$num[$cn2][$cn]*$num2[$cn][$cn3];
$sum=$sum+$pro;
}
echo '<input type="text"
value="'.$sum.'" style="width:40px" readonly>';
}
echo'<br>';
}
}
}
?>

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 65
Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 66
FLOWCHART No.28
To find two given matrices are compatible for multiplication, if yes print the
product of two matrices.

Prepared by: Bachelor of Science in Computer Science Students |2nd YEAR and 3rd YEAR| AY:2021-2022 67

You might also like