Professional Documents
Culture Documents
WPfile
WPfile
ON
WEB BASED PROGRAMMING
BCA 2st semester
Course code: BCA-
Session: 2022-23
<head></head>
<body>
SUM OF NUMBERS<br>
</form>
</html>
<?php
$no1=$_POST['num1'];
$no2=$_POST['num2'];
$a=$no1+$no2;
?>
OUTPUT:
PROGRAM-2
Write a PHP program to check prime number.
<html>
<head></head>
<body>
</form>
<?php
$n=$_POST['n1'];
$count=0;
if (($n%$i)==0) {
$count++;
} }
if ($count<3) {
else{
?>
OUTPUT:
PROGRAM-3
Write a PHP program to check even or odd number.
<html>
<head></head>
<body>
</form>
<?php
$n=$_POST['n1'];
if($n%2==0)
else {
?>
OUTPUT:
PROGRAM-4
Write a PHP program to print table of a number.
<html>
<head></head>
<body>
TABLE
</form>
<?php
$n=$_POST['n1'];
for($i=1;$i<=10;$i++)
$c=$i*$n;
?>
OUTPUT:
PROGRAM-5
Write a PHP program to print factorial of a number.
<html>
<head></head>
<body>
FACTORIAL CALCULATOR
</form>
<?php
$n=$_POST['n1'];
$factorial=1;
?>
OUTPUT:
PROGRAM-6
Write a PHP program to reverse given number.
<html>
<head></head>
<body>
TO REVERSE NUMBER
</form>
<?php
$n=$_POST['n1'];
$revnum = 0;
$rem = $n % 10;
$n = ($n / 10);
?>
OUTPUT:
PROGRAM-7
Write a PHP program to reverse given string.
<html>
<head></head>
<body>
</form>
<?php
$str=$_POST['string'];
$a=strrev("$str");
echo "$a";
?>
OUTPUT:
PROGRAM-8
Write a PHP program to swap two numbers with and without using
third variable.
SWAPPING WITH THIRD VARIABLE
<html>
<head></head>
<body>
</form>
<?php
$a =$_POST['num1'];
$b = $_POST['num2'];
$third = $a;
$a = $b;
$b = $third;
echo "First=".$a."
Second=".$b;
?>
SWAPPING WITHOUT THIRD VARIABLE
<html>
<head></head>
<body>
</form>
<?php
$a=$_POST['num1'];
$b=$_POST['num2'];
$a=$a+$b;
$b=$a-$b;
$a=$a-$b;
echo"After swapping<br>";
?>
OUTPUT:
PROGRAM-9
Write a PHP program to add, subtract, multiply & divide two
numbers using functions.
<html>
<head></head>
<body>
ARITHMATIC CALCULATOR<BR><BR>
</form>
</html>
<?php
function add()
$no1=$_POST['num1'];
$no2=$_POST['num2'];
$c=$no1+$no2;
add();
function sub()
$no1=$_POST['num1'];
$no2=$_POST['num2'];
$c=$no1-$no2;
sub();
function mul()
$no1=$_POST['num1'];
$no2=$_POST['num2'];
$c=$no1*$no2;
mul();
function div()
$no1=$_POST['num1'];
$no2=$_POST['num2'];
$c=$no1%$no2;
div();
?>
OUTPUT:
PROGRAM-10
Write a program to show the usage of SESSION variable.
<?php
session_start();
session_destroy();
?>
<html>
<body>
<?php
$_SESSION["NAME"] = "RONIT";
$_SESSION["AGE"] = "19";
?>
<?php
?>
<?php
if(isset($_SESSION["NAME"])){
unset($_SESSION["AGE"]);
?>
</body>
</html>
OUTPUT:
PROGRAM-11
Write a program to show the usage of $_POST , $_GET and
$_REQUEST variables.
Using REQUEST for the method
</form>
</form>
</form>
OUTPUT:
PROGRAM-12
Write a login form and validate it through PHP programming.
<html>
<head></head>
<body>
</form>
</html>
<?php
$user1=$_POST['user'];
$pass1=$_POST['pass'];
else
?>
OUTPUT: