1,2,4,7,11,16...n in PHP
<?php
/* 1,2,4,7,11,16...n. */
$l=1;
$a=1;
$b=1;
while($l<=10)
{
print"<br>".$a;
$a=$b+$a;
$b++;
$l++;
}
?>
Learn All Programming and Scripting languages inside Our Blog, learn all BCA, MCA, B.E.IT, B.E.CE programs here Our Youtube Channel: youtube.com/avadhtutor
<?php
/* 1,2,4,7,11,16...n. */
$l=1;
$a=1;
$b=1;
while($l<=10)
{
print"<br>".$a;
$a=$b+$a;
$b++;
$l++;
}
?>
<?php
/* 1,1,2,3,5,8,13,21....n. */
$a=1;
$b=0;
$c=0;
$l=1;
while($l<=10)
{
$c=$a+$b;
print"<br>".$c;
$a=$b;
$b=$c;
$l++;
}
?>
SUM OF SERIES IN PHP
<?php
/* 1,4,9,16,25,36....n.*/
$a=1;
$b=0;
while($a<=10)
{
$b=$a*$a;
print"<br>".$b;
$a++;
}
?>
OUTPUT : 1,4,9,16,25,36
<title>Write a program to Find Vowel or Not Vowel in PHP</title>
</head>
<body>
<?php
/* Write a program to get the one character from user and find out
this character is vowel or not.*/
$x='a';
if($x=='a'|$x=='e'|$x=='i'|$x=='o'|$x=='u'|$x=='A'|$x=='E'|$x=='I'|$x=='O'|$x=='U')
{
print"Vowel";
}
else
{
print"Not Vowel";
}
?>
<title>Write a program to accept any year four digits and check whether it is leap year or not</title>
<?php
/* Write a program to accept any year four digits and check
whether it is leap year or not.*/
$y=2000;
if($y%4==0)
{
print"Leap Year";
}
else
{
print"Not Leap Year";
}
?>
<title>Write a program to accept any number and check wether it is divisible by 9 ot not</title>
<?php
/* Write a program to accept any number and check wether it is
divisible by 9 ot not.*/
$n=3;
if($n%9==0)
{
print"Divisible";
}
else
{
print"Not Divisible";
}
?>
Write a program that reads 10 element in array enter a number and find how many times the number is repeated in the list In PHP
Example:
<title>PHP:Write a program that reads 10 element in array enter a number and find how many times the number is repeated in the list </title>
<?php
/* Write a program that reads 10 element in array enter a number and find how many times the number is repeated in the list.*/
$n=array(1,2,9,4,5,9,7,8,9,10,9);
$sv=9;
$count=0;
for($a=1;$a<=10;$a++)
{
if($n[$a]==$sv)
{
$count++;
}
}
print"Searching values is found times = ".$count."<br>";
?>
</body>
</html>
<title>PHP : Write a program that reads 10 element in array count how many zero how many positive and how many negative values</title>
EXAMPLE:
<?php
/* Write a program that reads 10 element in array count how many zero how many positive and how many negative values.*/
$n=array(1,-2,3,-4,5,-6,7,8,9,10,0);
$b=0;
$c=0;
$d=0;
for($a=1;$a<=10;$a++)
{
if($n[$a]<0)
{
$b++;
}
if($n[$a]>0)
{
$c++;
}
if($n[$a]==0)
{
$d++;
}
}
print"Positive Number = ".$b."<br>";
print"negative Number = ".$c."<br>";
print"Zero Number = ".$d;
?>
OUTPUT:
Positive Number = 3
negative Number = 6
Zero Number = 1
Example:
<title>PHP: Write a program that reads 10 element and print all even values form them Using PHP</title>
<?php
/* Write a program that reads 10 element and print all even values form them.*/
$n=array(1,2,3,4,5,6,7,8,9,10);
for($a=1;$a<=10;$a++)
{
if($n[$a]%2==0)
{
print"<br>"."Odd Number = ".$n[$a];
}
}
?>
OUTPUT:
Even Number = 2
Even Number = 4
Even Number = 6
Even Number = 8
Even Number = 10
Example:
<title>PHP: Write a program that reads 10 element and print all odd values from them </title>
<?php
/* Write a program that reads 10 element and print all odd values from them.*/
$n=array(1,2,3,4,5,6,7,8,9,10,11);
for($a=1;$a<=10;$a++)
{
if($n[$a]%2!=0)
{
print"<br>"."Odd Number = ".$n[$a];
}
}
?>
OUTPUT:
Odd Number = 1
Odd Number = 3
Odd Number = 5
Odd Number = 7
Odd Number = 9
Odd Number = 11
Example :
<title>PHP : Write a program to sort array of elements using bubble sort.</title>
<?php
/* Write a program to sort array of elements using bubble sort. */
$n=array(9,8,7,6,5,4,3,2,1,0);
$temp=0;
for($b=0;$b<=9;$b++)
{
if($n[$b]<$n[$b-1])
{
$temp=$n[$b];
$n[$b]=$n[$b-1];
$n[$b-1]=$temp;
}
}
print"After Sorting";
for($a=0;$a<=8;$a++)
{
print"<br>".$n[$a];
}
?>
Example :
<title>Write a program to get 10 student mark from user and sort it in ascending order</title>
<?php
/* Write a program to get 10 student mark from user and sort it in ascending order. */
$n=array(2,1,5,6,4,3,0,8,9,7);
for($a=0;$a<=9;$a++)
{
for($b=$a+1;$b<=9;$b++)
{
if($n[$a]>$n[$b])
{
$temp=$n[$a];
$n[$a]=$n[$b];
$n[$b]=$temp;
}
}
}
print"Asending Number";
for($a=0;$a<10;$a++)
{
print"<br>".$n[$a];
}
?>