63 189
Assignments Done
99,3%
Successfully Done
In July 2018

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”.
Expert's answer
<?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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions