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

Programs

Uploaded by

ntanmayi13
Copyright
© © All Rights Reserved
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)
19 views7 pages

Programs

Uploaded by

ntanmayi13
Copyright
© © All Rights Reserved
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

Assignment 1

1. Write a program to print “Your Full name” using echo


2. Write a program to print “first name middle name last name” using variable
3. Write a program to print two variables in single echo
4. Write a program to perform addition of two numbers
5. Write a program to perform subtraction of two numbers
6. Write a program to perform multiplication of two numbers
7. Write a program to perform division of two numbers

Assignment 2
1. Write a program to check whether the person is adult or not.

2. Write a program to check student grade based on marks using if else if


statement.
Conditions:
 If marks are 60% or more, grade will be First Division.
 If marks between 45% to 59%, grade will be Second Division.
 If marks between 33% to 44%, grade will be Third Division.
 If marks are less than 33%, student will be Fail.

3. Write a program to show day of the week (for example: Monday) based on
numbers using switch/case statements.
Conditions:
 You can pass 1 to 7 number in switch
 Day 1 will be considered as Monday
 If number is not between 1 to 7, show invalid number in default

Assignment 3
1. Write a program to print “TCET” 5 times using do while loop
2. Write a factorial program using for loop in php
3. Write a Program to create given pattern with * using for loop
4. Write a program to print all even numbers between 1 to 10 using while loop
5. Write a program to print all odd numbers between 1 to 10 using while loop
If statement
<!DOCTYPE html>
<html>
<body>
<?php
$num=12;
if($num<100){
echo "$num is less than 100";
}
?>
</body>
</html>

If else Statement
<!DOCTYPE html>
<html>
<body
<?php
$num=12;
if($num%2==0){
echo "$num is even number";
}else{
echo "$num is odd number";
}
?>
</body>
</html>

If else if statement
<!DOCTYPE html>
<html>
<body>
<?php
$marks=69;
if ($marks<33){
echo "fail";
}
else if ($marks>=34 && $marks<50) {
echo "D grade";
}
else if ($marks>=50 && $marks<65) {
echo "C grade";
}
else if ($marks>=65 && $marks<80) {
echo "B grade";
}
else if ($marks>=80 && $marks<90) {
echo "A grade";
}
else if ($marks>=90 && $marks<100) {
echo "A+ grade";
}
else {
echo "Invalid input";
}
?>
</body>
</html>

Nested IF
<!DOCTYPE html>
<html>
<body>

<?php
$age = 23;
$nationality = "Indian";
//applying conditions on nationality and age
if ($nationality == "Indian")
{
if ($age >= 18) {
echo "Eligible to give vote";
}
else {
echo "Not eligible to give vote";
}
}
?>
</body>
</html>

Switch Case Statement


<!DOCTYPE html>
<html>
<body>
<?php
$num=20;
switch($num){
case 10:
echo("number is equals to 10");
break;
case 20:
echo("number is equal to 20");
break;
case 30:
echo("number is equal to 30");
break;
default:
echo("number is not equal to 10, 20 or 30");
}
?>
</body>
</html>

For loop to display 1 to 10 numbers


<!DOCTYPE html>
<html>
<body>
<?php
for($n=1;$n<=10;$n++){
echo "$n<br/>";
}
?>
</body>
</html>

While loop to display 1 to 10 numbers


<!DOCTYPE html>
<html>
<body>
<?php
$n=1;
while($n<=10){
echo "$n<br/>";
$n++;
}
?>
</body>
</html>

Do while loop to display 1 to 10 numbers


<!DOCTYPE html>
<html>
<body>
<?php
$n=1;
do{
echo "$n<br/>";
$n++;
}while($n<=10);
?>
</body>
</html>

You might also like