Ad here

Monday, December 15, 2014

PHP HyperTextPreprocessor Tutorial Point Learn Easily PHP ( Part 2 )

Conditional statements :-
1.if (one way selection )
2.if else(two way selection )
3.if else if
4. switch case ( 3 & 4 both are multiway selection )

If:-

<?php        
$n=8;
If ($n==10)
{
Echo” value is 10”;
}
?>
If else:-
<?php
$p=50;
if(condition )
{
echo" statement 1";
}

 else
{
echo" statement 2";
}

?>
If else if :-

<body>
<?php
$p=50;
if(cond 1)
{
echo" statement 1";
}

 else if (cond 2)
{
echo" statement 2";
}
 else if (cond 3)
{
echo" statement 3";
}
else if(cond 4)
{
echo" statement 4";
}
else  
{
echo" statement 5";
}
?>

Switch Case:-
<body>
<?php
 $ch="a";
$a=10;
$b=5;
switch ($ch){
 case 'a':
 {
Case a formula
break;
 }
  case 'b':
 {
Case b formula
break;
 }
  case 'c':
 {
Case c formula
break;
 }
 default:
 {
 echo" you entered wrong value ";
 break;
 }
 }
Q1.Enter two numbers and find out greatest no. using if else?
Solution Code:-
<title>rahuljaincse.blogspot.com</title>
</head>
 <body>
<?php
$b=20;
if($b>18)
{
echo"person is eligible for voting:".$b;
}
else
{
echo"person is not eligible for the voting ";
}
 ?>
 </body>
Q2.Enter any age of person and find out person is eligible for voting or not?
Solution Code:-
<title>rahuljaincse.blogspot.com</title>
</head>
 <body>
<?php
$b=10;
if($b%5==0)
{
echo"your digit is divisible by 5:";
}
else
{
echo"your digit is  not divisible by 5 ";
}
 ?>
 </body>
</html>
Q3.Enter any digit and find out digit is devisible  by 5 or not?
<?php
$a=10;
If($a%5==0)
{
Echo “number is devisible by 5”;
}
Else
{
Echo “number is not devisible by 5”;
}
 ?>
Q4.Enter any percentage of students and print student belongs to which category?
80%---------A+
70-80%--------A
60-70%----------B+
50- 60%------------B
40-50%-----------------C
Less than 40 -----------Fail
Solution code:-
<title> rahuljaincse.blogspot.com</title>
</head>
 <body>
<?php
$p=50;
if($p>80)
{
echo" grade is A+";
}
 else if ($p<=80&&$p>70)
{
echo" grade is A";
}
 else if ($p<=70&&$p>60)
{
echo" grade is B+";
}
else if($p<=60&&$p>50)
{
echo" grade is B";
}
else if($p<=50&&$p>40)
{
echo" grade is C";
}
 else if  ($p<=40)
{
echo" grade is Fail";
}
?>
 </body>
</html>
 Q5.calculate area of circle ,Rectangle ,and triangle using Switch case?  
Solution Code:-
<title>rahuljaincse.blogspot.com</title>
</head>
<body><?php
 $ch="circle";
$a=10;
$b=5;
switch ($ch){
 case 'triangle':
 {
 $c=1/2*$a*$b;
 echo"area of triangle is".$c;
 break;
 }
  case 'circle':
 {
 $c=3.14*$a*$a;
 echo"area of circle is".$c;
 break;
 }
  case 'rectangle':
 {
 $c=$a*$b;
 echo"area of rectangle  is".$c;
 break;
 }
 default:
 {
 echo" you entered wrong value ";
 break;
 }
 }

No comments:

Post a Comment