Assi No1
Assi No1
Program no : 01
Name :Kumbhar Ghanashyam Basaveshwar.
Class :BCA-II Roll no: 59
Program Name: Write a php program to swap two numbers with variable
____________________________________________________________________
Program Code :
<?php
$a=(int)readline("Enter a=");
$b=(int)readline("Enter b=");
echo"\nBefore swapping:".$a.','.$b;
$c=$a;
$a=$b;
$b=$c;
echo"\nAfter swapping:".$a.','.$b;
?>
*/OUTPUT
<?php
$a=(int)readline("Enter a=");
$b=(int)readline("Enter b=");
echo"\nBefore swapping:".$a.','.$b;
$a=$a+$b;
$b=$a-$b;
$a=$a-$b;
echo"\nAfter swapping:".$a.','.$b;
?>
*/OUTPUT
Before swapping:5,6
After swapping:6,5
-------------------------------------------------------------------------------------------------------
Program no : 03
Name :Kumbhar Ghanashyam Basaveshwar.
Class :BCA-II Roll no: 59
Program Name: Write a php program to find the factorial of a number.
___________________________________________________________________
Program Code :
<?php
$num =4;
$factorial=1;
for($x=$num;$x>=1;$x--)
{
$factorial=$factorial*$x;
}
echo"factorial of $num is $factorial";
?>
*/OUTPUT :
<?php
function countWords($str) {
return str_word_count($str);
}
$string = "Jaysingour college jaysingpur";
echo "Total number of words: " . countWords($string);
?>
*/OUTPUT :
<?php
function countWordOccurrence($str, $word) {
$words = str_word_count(strtolower($str), 1);
$wordCount = array_count_values($words);
return isset($wordCount[strtolower($word)]) ? $wordCount[strtolower($word)] : 0;
}
$string = "jaysingpur college jaysingpur";
$searchWord = "jaysingpur";
echo "The word '$searchWord' appears " . countWordOccurrence($string,
$searchWord) . " times in
the string.";
?>
*/OUTPUT :
<?php
function replaceWord($str, $searchWord, $replaceWord) {
return str_ireplace($searchWord, $replaceWord, $str);
}
$string = "sangli college sangli";
$searchWord = "sangli";
$replaceWord = "jaysingpur";
echo "Original string: " . $string . "<br>";echo "\nModified string: " .
replaceWord($string, $searchWord, $replaceWord);
?>
*/OUTPUT :
<?php
function areaOfTriangle($base, $height) {
return 0.5 * $base * $height;
}
function areaOfRectangle($length, $width) {
return $length * $width;
}
$triangleBase = 10;
$triangleHeight = 5;
$rectangleLength = 8;
$rectangleWidth = 4;
$triangleArea = areaOfTriangle($triangleBase, $triangleHeight);
$rectangleArea = areaOfRectangle($rectangleLength, $rectangleWidth);
echo "The area of the triangle is: " . $triangleArea . " square units.<br>";
echo "\nThe area of the rectangle is: " . $rectangleArea . " square units.<br>";
?>
Outout:
jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ gedit areatriangle.php
jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ php areatriangle.php
The area of the triangle is: 25 square units.<br>
The area of the rectangle is: 32 square units.<br>
-------------------------------------------------------------------------------------------------------
Program no : 02
Name :Kumbhar Ghanashyam Basaveshwar.
Class :BCA-II Roll no: 59
Program Name:write a php program to find the GCD of two numbers using user-
defined functions
___________________________________________________________________
Program Code :
<?php
function findGCD($a, $b) {
while ($b != 0) {
$temp = $b;
$b = $a % $b;
$a = $temp;
}
return $a;
}
$num1 = 56;
$num2 = 98;
$gcd = findGCD($num1, $num2);
echo "The GCD of $num1 and $num2 is: $gcd";?>
Output:
<?php
function findBiggestNumber($arr) {
$biggest = $arr[0];
for ($i = 1; $i < count($arr); $i++) {
if ($arr[$i] > $biggest) {
$biggest = $arr[$i];
}
}
return $biggest;
}
$numbers = [10, 45, 23, 67, 89, 12, 55];
$biggestNumber = findBiggestNumber($numbers);
echo "The biggest number in the array is: " . $biggestNumber;
?>
Output:
<?php
$numbers = [10, 45, 23, 67, 89, 12, 55];
$smallest = $numbers[0];
foreach ($numbers as $number) {
if ($number < $smallest) {
$smallest = $number;
}
}
echo "The smallest number in the array is: " . $smallest;
?>
Output:
<?php
$number=1233456;
if($number%2==0)
{
echo "$number is Even Number";
}else
{
echo "$number is Odd Number";
}
?>
Output:
<?php
function isLeap($year)
{
return (date('L', mktime(0, 0, 0, 1, 1, $year))==1);
}
for($year=2011; $year<2016; $year++)
{
If (isLeap($year))
{
echo "$year : LEAP YEAR\n";
}
else
{
echo "$year : Not leap year\n";
}
}
?>
Output:
jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ gedit leapyear.php
jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ php leapyear.php
2011 : Not leap year
2012 : LEAP YEAR
2013 : Not leap year
2014 : Not leap year
2015 : Not leap year
-------------------------------------------------------------------------------------------------------
Program no : 07
Name :Kumbhar Ghanashyam Basaveshwar.
Class :BCA-II Roll no: 59
Program Name:Write a php program for showing prime numbers
___________________________________________________________________
Program Code :
<?php
$count = 0;
$num = 2;
while ($count < 15 )
{
$div_count=0;
for ( $i=1; $i<=$num; $i++)
{
if (($num%$i)==0)
{
$div_count++;
}
}
if ($div_count<3)
{
echo $num." , ";
$count=$count+1;
}
$num=$num+1;
}
?>
Output: