Online Shopping Project

You might also like

You are on page 1of 5

PROGRAM 01: WAP using for loop and display sum of all even numbers

between 1 and 100


<?php

$sum=0;

for($i=1; $i<=100; $i++)

if($i%2==0)

$sum=$sum+$i;

echo "Sum of even no.'s between 1 to 100: $sum";

?>
PROGRAM 02: WAP to display pattern using nested for loop
<?php

for($i=1;$i<=5;$i++)

for($j=1;$j<=$i;$j++)

echo "*";

echo "<br>";

?>
PROGRAM 03: WAP using the string ‘mary had a little lamb’ display string
function
<?php

$str='Mary had a little lamb';

echo "<b> String: $str </b><br><br>";

echo "Length of string: ".strlen($str)."<br><br>";

echo "Reversal of string: ".strrev($str)."<br><br>";

echo "Substr(4,10): ".substr($str,4,10)."<br><br>";

echo "No. of words: ".str_word_count($str,0)."<br><br>";

echo "Uppercase string: ".strtoupper($str)."<br><br>";

echo "Lowercase string: ".strtolower($str)."<br><br>";

echo "ucwords(): ".ucwords($str)."<br><br>";

echo "ucfirst(): ".ucfirst($str);

?>
PROGRAM 04: WAP to count and display numbers of a and l in “mary had a
little lamb”.
<?php

$a="mary had a little lamb";

$acount=0;

$lcount=0;

for($i=0;$i<=strlen($a);$i++)

if(substr($a,$i,1)=='a')

$acount=$acount+1;

if(substr($a,$i,1)=='l')

$lcount=$lcount+1;

echo "count of a= ".$acount."\n";

echo "<br>";

echo "count of l= ".$lcount."\n";

?>
PROGRAM 05: WAP to display the table with 10 rows and 10 columns showing
all possible 2 digit combinations.

You might also like