Thursday, 4 March 2021

Write a program that reads 10 element in array count how many odd values and how many even values in the list in php

Write a program that reads 10 element in array count how many odd values and how many even values in the list in php


Example:


<title>PHP: Write a program that reads 10 element in array count how many odd values and how many even values in the list in php</title>

<?php
/* Write a program that reads 10 element in array count how many odd values
and how many even values in the list.*/
$n=array(2,1,4,6,10,12,13,14,15,16,17);
$b=0;
$c=0;
for($a=1;$a<=10;$a++)
{
if($n[$a]%2==0 or $n[$a]==0)
{
$c++;
}
else
{
$b++;
}
}
print"Odd Number = ".$b."<br>";
print"Even Number = ".$c;
?>


Output:

Odd Number = 4
Even Number = 6

No comments:

Post a Comment