Write php code that will calculate and print the sum of all numbers less than 100. If the sum is even, print “even” to the web page; otherwise, print “odd”.
1
Expert's answer
2013-03-07T10:18:03-0500
<?php $sum=0;
for($i=0;$i<=99;$i++){ $sum=$sum+$i;}
echo "The total was ", $sum," which is ";
if ($sum%2==0){ echo "even";}
if ($sum%2==1){ echo "odd";}
?>
The second If check is redundant because if a number is not even it is going to be odd so you could use:
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment