0% found this document useful (0 votes)
15 views13 pages

Assi No1

The document contains a series of PHP programs written by Kumbhar Ghanashyam Basaveshwar, a BCA-II student, showcasing various programming tasks such as swapping numbers, calculating factorials, counting words, and finding GCD. Each program includes the code, expected output, and the context of the task. The programs demonstrate fundamental programming concepts and functions in PHP.

Uploaded by

uiuxnihal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views13 pages

Assi No1

The document contains a series of PHP programs written by Kumbhar Ghanashyam Basaveshwar, a BCA-II student, showcasing various programming tasks such as swapping numbers, calculating factorials, counting words, and finding GCD. Each program includes the code, expected output, and the context of the task. The programs demonstrate fundamental programming concepts and functions in PHP.

Uploaded by

uiuxnihal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 13

-------------------------------------------------------------------------------------------------------

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

jcj-bca-pc24@jcjbcapc24:~/SHYAM/PHP$ php variable.php


Enter a=5
Enter b=4
-------------------------------------------------------------------------------------------------------
Program no : 02
Name :Kumbhar Ghanashyam Basaveshwar.
Class :BCA-II Roll no: 59
Program Name:Write php program to swap two numbers without using third
variable.
____________________________________________________________________
Program Code :

<?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

jcj-bca-pc24@jcjbcapc24:~/SHYAM/PHP$ gedit 3variable.php


jcj-bca-pc24@jcjbcapc24:~/SHYAM/PHP$ php 3variable.php
Enter a=5
Enter b=6

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 :

jcj-bca-pc24@jcjbcapc24:~/SHYAM/PHP$ gedit factorrial.php


jcj-bca-pc24@jcjbcapc24:~/SHYAM/PHP$ php factorrial.php
factorial of 4 is factorial
-------------------------------------------------------------------------------------------------------
Program no : 04
Name :Kumbhar Ghanashyam Basaveshwar.
Class :BCA-II Roll no: 59
Program Name: Write a php program to count the total number of wordin in string
___________________________________________________________________
Program Code :

<?php
function countWords($str) {
return str_word_count($str);
}
$string = "Jaysingour college jaysingpur";
echo "Total number of words: " . countWords($string);
?>

*/OUTPUT :

jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ gedit totalnum.php


jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ php totalnum.php
Total number of words: 3
-------------------------------------------------------------------------------------------------------
Program no : 05
Name :Kumbhar Ghanashyam Basaveshwar.
Class :BCA-II Roll no: 59
Program Name: Write a php program to find the occurance of a word in a string
___________________________________________________________________
Program Code :

<?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 :

jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ gedit occurrence.php


jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ php occurrence.php
The word 'jaysingpur' appears 2 times in
the string
-------------------------------------------------------------------------------------------------------
Program no : 06
Name :Kumbhar Ghanashyam Basaveshwar.
Class :BCA-II Roll no: 59
Program Name:Write a php program to replace word in a string.
___________________________________________________________________
Program Code :

<?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 :

jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ gedit replace.php


jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ php replace.php
Original string: sangli college sangli<br>
Modified string: jaysingpur college jaysingpur
-------------------------------------------------------------------------------------------------------
Program no : 01
Name :Kumbhar Ghanashyam Basaveshwar.
Class :BCA-II Roll no: 59
Program Name:Write a php program to find area of triangle and rectangle using
functions
___________________________________________________________________
Program Code :

<?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:

jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ gedit gcd.php


jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ php gcd.php
The GCD of 56 and 98 is: 14
-------------------------------------------------------------------------------------------------------
Program no : 03
Name :Kumbhar Ghanashyam Basaveshwar.
Class :BCA-II Roll no: 59
Program Name:Write a php program for finding the biggest number in an array
without using any array function
___________________________________________________________________
Program Code :

<?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:

jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ gedit array.php


jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ php array.php
The biggest number in the array is: 89
-------------------------------------------------------------------------------------------------------
Program no : 04
Name :Kumbhar Ghanashyam Basaveshwar.
Class :BCA-II Roll no: 59
Program Name:Write a php program for finding smallest number in an array
___________________________________________________________________
Program Code :

<?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:

jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ gedit smallarray.php


jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ php smallarray.php
The smallest number in the array is: 10
-------------------------------------------------------------------------------------------------------
Program no : 05
Name :Kumbhar Ghanashyam Basaveshwar.
Class :BCA-II Roll no: 59
Program Name:Write a php program for find number is even or odd
___________________________________________________________________
Program Code :

<?php
$number=1233456;
if($number%2==0)
{
echo "$number is Even Number";
}else
{
echo "$number is Odd Number";
}
?>

Output:

jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ gedit evenlodd.php


jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ php evenlodd.php
1233456 is Even Number
-------------------------------------------------------------------------------------------------------
Program no : 06
Name :Kumbhar Ghanashyam Basaveshwar.
Class :BCA-II Roll no: 59
Program Name:Write a php program for find year is leap or not
___________________________________________________________________
Program Code :

<?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:

jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ gedit prime.php


jcj-bca-pc24@jcjbcapc24:~/SHYAM/php$ php prime.php
2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 ,

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy