Professional Documents
Culture Documents
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
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.
𝟏 + 𝐱 𝟏 + 𝐱 𝟐 + 𝐱 𝟑 +. . . . . + 𝐱 𝐧 .
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.
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
//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
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
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
<?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
$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
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";
}
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"/>';
}
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;
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: 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
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
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
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
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"  "; 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"  ";}
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:
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);
//print output
echo $rev;
}
?>
Output:
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
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