<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
No comments:
Post a Comment