0% found this document useful (0 votes)
131 views7 pages

AIM:-Write Programme in PHP 1. Write A PHP Program To Print Your Basic Details

The document contains 5 PHP programs: 1. A program to print basic details like name, enrollment number, semester, and year in a formatted output. 2. A basic calculator program that takes input from an HTML form, performs operations like addition, subtraction, multiplication, and division based on the selected operator, and displays the output. 3. A program to reverse a given number by repeatedly taking modulo and dividing the number. 4. A program to calculate the sum of digits of a given number. 5. A program to calculate the factorial of a given number by multiplying from the number down to 1.

Uploaded by

Sanket Shah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views7 pages

AIM:-Write Programme in PHP 1. Write A PHP Program To Print Your Basic Details

The document contains 5 PHP programs: 1. A program to print basic details like name, enrollment number, semester, and year in a formatted output. 2. A basic calculator program that takes input from an HTML form, performs operations like addition, subtraction, multiplication, and division based on the selected operator, and displays the output. 3. A program to reverse a given number by repeatedly taking modulo and dividing the number. 4. A program to calculate the sum of digits of a given number. 5. A program to calculate the factorial of a given number by multiplying from the number down to 1.

Uploaded by

Sanket Shah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

AIM:-Write Programme in PHP 1. Write a PHP program to print your basic details.

Snapshot:-

Code:<html> <head> <head> <body bgcolor="yellow"> <?php echo"<h1><b><u>Basic Details</u></b></h1> "; echo"Name:- Sanket j.shah<br>"; echo"Enrollment No:- 110753116008<br>"; echo"Semester:-6<br>"; echo"Year:- 2012-13"; ?> </body> </html>

2. Write a PHP program to make a calculator. You can enter numbers from HTML page and transfer to PHP page. Snapshot:-

[Cal.php] Code:Cal.php <html> <head> </head> <body bgcolor="lightgreen"> <form method="get" action="calc1.php"> <center> <h1>Calculator</h1> <hr> <h3>Enter First Value:-&nbsp;&nbsp;&nbsp;

[Cal1.php]

<input type="text" name="t1"><br><hr>

<h3>Enter Second Value:- <input type="text" name="t2"><br><hr> <input type="Submit" value="+" name="choice"> <input type="Submit" value="-" name="choice"> <input type="Submit" value="*" name="choice"> <input type="Submit" value="/" name="choice"> <input type="Reset" value="Reset"> </center> </form> </body> </html>

Cal1.php <html> <head> </head> <body bgcolor="lightpink"> <center> <hr> <h1> Your Ans is: <?php $first=$_GET['t1']; $second=$_GET['t2']; $choice=$_GET['choice']; switch($choice) { case '+': { echo $first+$second; break; } case '-': { echo $first-$second; break; } case '*': { echo $first*$second; break; } case '/': { echo $first/$second; break;

} } ?> </h1> <hr> <a href="cal.php">GoBack</a> </center> </body> </html> 3. Write a PHP program to print reverse number. Snapshot:-

[p3.php] Code:<html> <head> </head> <body bgcolor="yellow"> <form method="get" action="p5.php"> <center> <table border="0"> <tr>

[p5.php]

<td><form>Number:<input type="text" name="t"></td> <td><input type="submit"value="submit" ></td> </tr> <table> </form> </center> </font>

</body> </html> P5.php <?php $num = $_GET["t"]; $revnum=0; do{ $revnum=($revnum *10)+($num % 10); $num=(int)($num / 10 ); }while($num>0); echo "Your Reverse number is $revnum"; ?>

4. Write a PHP program to print sum of digit Snapshot:-

[p3.php] Code:P3.php <html> <head> </head> <body bgcolor="yellow"> <form method="get" action="p4.php"> <center> <table border="0"> <tr>

[p4.php]

<td><form>Number:<input type="text" name="t"></td>

<td><input type="submit"value="submit" ></td> </tr> <table> </form> </center> </font> </body> </html> P4.php <?php $sum=0; $d; $n; $t=$_GET["t"]; $m=&$t; while($t>0) { $d = $t % 10 ; $t = $t / 10 ; $sum = $sum + $d; } echo "Your sum of digit $sum"; ?> 5. Write a PHP program to print factorial number. Snapshot:-

[p3.php]

[p2.php]

Code:P3.php <html> <head> </head> <body bgcolor="yellow"> <form method="get" action="p2.php"> <center> <table border="0"> <tr> <td><form>Number:<input type="text" name="t"></td> <td><input type="submit"value="submit" ></td> </tr> <table> </form> </center> </font> </body> </html> P2.php <?php $num = $_GET["t"]; $factorial = 1; for ($x=$num; $x>=1; $x--) { $factorial = $factorial * $x; } echo "Factorial of $num is $factorial"; ?>

You might also like