Answer to Question #25739 in C++ for Bronue-

Question #25739
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:

if ($sum%2==0){
echo "even";}

else{
echo "odd";}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS