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

Web Tech Lab Programs

The document contains multiple PHP, JavaScript, and JSP programs demonstrating various programming concepts such as Armstrong numbers, factorial calculations, leap year checks, reversing numbers, and finding the greatest of three numbers. Each program includes HTML forms for user input and corresponding scripts to process the input and display results. The document serves as a practical guide for students in the Web Technology Lab at Guru Nanak Institute of Technology.

Uploaded by

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

Web Tech Lab Programs

The document contains multiple PHP, JavaScript, and JSP programs demonstrating various programming concepts such as Armstrong numbers, factorial calculations, leap year checks, reversing numbers, and finding the greatest of three numbers. Each program includes HTML forms for user input and corresponding scripts to process the input and display results. The document serves as a practical guide for students in the Web Technology Lab at Guru Nanak Institute of Technology.

Uploaded by

POULAMI GAIN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

GURUNANAK INSTITUTE OF TECHNOLOGY

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Web Technology Lab

CS 792C

Name : Poulami Gain

University Roll number : 500120020025

Registration number :201430100110146

Guru Nanak Institute of Technology, Kolkata-700114


1. WAP in PHP, to demonstrate armstrong number.

<html>
<body>
<form method="post">Enter
the Number:
<input type="number" name="number">
<input type="submit" value="Submit">
</form>
</body>
</html>
<?php
if($_POST)
{
$number = $_POST['number'];
$a = $number;
$sum = 0;
while( $a != 0 )
{
$rem = $a % 10;
$sum = $sum + ( $rem * $rem * $rem );
$a = $a / 10;
}
if( $number == $sum )
{
echo "Yes $number an Armstrong Number";
}
else
{
echo "$number is not an Armstrong Number";
}
}
?>

Output:
2. WAP in PHP, to demonstrate factorial of a number.

<html>
<head>
<title>Factorial Program using loop in PHP</title>
</head>
<body>
<form method="post">
Enter the Number:<br>
<input type="number" name="number" id="number">
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if($_POST){
$fact = 1;
//getting value from input text box 'number'
$number = $_POST['number'];
echo "Factorial of $number:<br><br>";
//start loop
for ($i = 1; $i <= $number; $i++){
$fact = $fact * $i;
}
echo $fact . "<br>";
}
?>
</body>
</html>

Output:
3. WAP in PHP, to demonstrate Leap Year.

<html>
<body>
<form method="post">
Enter the Year: <input type="text" name="year">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
if($_POST)
{
//get the year
$year = $_POST['year'];
//check if entered value is a number
if(!is_numeric($year))
{
echo "Strings not allowed, Input should be a number";return;
}
//multiple conditions to check the leap year
if( (0 == $year % 4) and (0 != $year % 100) or (0 == $year % 400) )
{
echo "$year is a Leap Year";
}
else
{
echo "$year is not a Leap Year";
}
}
?>

Output:
4. WAP in PHP, to demonstrate Reversing a number and Palindrome number.

<html>
<head>
<title>Reverse and palindrom of number</title>
</head>
<body>
<form method="post">
Enter The Number: <br>
<input type="number" name="number" id="number">
<input type="submit" name="submit" value="submit">
</form>
<?php

$n=$_POST['number'];
$temp=$n;
$rev=0;

echo "Reverse of the digits of the given number is: ";


while($n>0)
{
$rem=$n%10;
$rev=$rev*10+$rem;
$n=(int)($n/10);

}
echo $rev."<br><br>";

if($rev==$temp)
echo "Number is a palindrom number";else
echo "Number is non palimdrom";
?>
</body>
</html>

Output:
5. WAP in PHP, to demonstrate sum of digits of a number.

<html>
<head>
<title>Summation of each Digit in PHP</title>
</head>
<body>
<form method="post">
Enter the Number:<br>
<input type="number" name="number" id="number">
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if($_POST){
$sum = 0;
$number = $_POST['number'];
echo "Summation of each digit of $number:<br><br>";while($number!=0)
{
$rem=$number%10;
$sum = $sum + $rem;
$number=$number/10;
}
echo $sum . "<br>";
}
?>
</body>
</html>

Output:
6. WAP in JavaScript, to demonstrate armstrong number.

<html>
<head>CLIENT SIDE SCRIPTING
</head>
<body style="text-align:center;font-size:35px">
<h2>ARMSTRONG NO CHECKING :</h2>
Enter an integer no: <input id="textbox">
<br><br>
<button onclick="Armstrong()">Check</button>
<p id="para"></p>
<script>
function Armstrong()
{ var r,n,temp,sum;sum=0;
n=document.getElementById("textbox").value;temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=parseInt(n/10);
}
if(temp==sum)
document.getElementById("para").innerHTML="Armstrong Number";else
document.getElementById("para").innerHTML="Non-Armstrong
Number";
}
</script>
</body>
</html>

Output:
7. WAP in JavaScript, to demonstrate factorial of a number.

<html>
<head>CLIENT SIDE SCRIPTING
</head>
<body style="text-align:center;font-size:35px">
<h2>FACTORIAL OF A GIVEN NUMBER :</h2>
Enter an integer no: <input id="textbox">
<br><br>
<button onclick="Factorial()">Factorial</button>
<p id="para"></p>
<script>
function Factorial()
{ var a,n,f;f=1;
n=document.getElementById("textbox").value;for(a=1;a<=n;a++)
{
f=f*a;
}
document.getElementById("para").innerHTML="Factorial of the no
is="+f; }
</script>
</body>
</html>

Output:
8. WAP in JavaScript, to demonstrate the fibonacci series.

<html>
<head>
<title> Fibonacci Series in JavaScript </title>
</head>
<body>
<script>
var n1 = 0, n2 = 1, next_num, i;
var num = parseInt (prompt("Enter the limit for Fibonacci Series"));document.write( "Fibonacci
Series: ");
for ( i = 1; i <= num; i++)
{ document.write (" <br> " + n1);
next_num = n1 + n2;
n1 = n2;
n2 = next_num;
}

</script>
</body>
</html>

Output:
9. WAP in JSP, to demonstrate factorial of a number.

<html>
<head>
<title> Factorial usin JSP</title>
</head>
<body>
<form name="f1" method="post" action="factorial.jsp">
Enter the number : <input type="text" name="n"></input>
<input type="submit" name="submit" value="submit"></input>
</form>
<%!
int facto(int n)
{
int i;
int fact=1;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
return fact;

}
%>

<%
String inp=request.getParameter("n");
if(inp!=null)
{
int px=Integer.parseInt(inp);

int x=facto(px);

out.println("Factorial = "+x);
}
%>
</body>
</html>

Output:
10. WAP in JSP, to demonstrate greatest of 3 numbers.

<html>
<head>
<title> Greatest among 3 no </title>
</head>
<body>
<%!
int greatest(int a,int b,int c)
{
if(a>b)
{
if(a>c)
return a;
else
return c;
}
else
{
if(b>c)
return b;
else
return c;

}
}
%>
<%
String a1=request.getParameter("n1");
String b1=request.getParameter("n2");
String c1=request.getParameter("n3");
%>
<form name="f1" method="post" action="greatest.jsp">
Enter 1st No: <input type="text1" name="n1" value="<% out.println(a1); %>">
</input>
<br><br>
Enter 2nd No: <input type="text2" name="n2" value="<% out.println(b1); %>">
</input>
<br><br>
Enter 3rd No: <input type="text3" name="n3" value="<% out.println(c1); %>">
</input>
<br><br>
<input type="submit" name="submit" value="submit"></input>
</form>
<%
if(a1!=null && b1!=null && c1!=null)
{
programs.md 2023-11-28
18 / 18
int a=Integer.parseInt(a1);
int b=Integer.parseInt(b1);
int c=Integer.parseInt(c1);
int x=greatest(a,b,c);
out.println("Greatest= "+x);
}
%>
</body>
</html>

Output:

You might also like