Cs 2205 Programming Assignment Unit 7
Cs 2205 Programming Assignment Unit 7
Solution:
/*
Program 1: Write a program in PHP using a ‘for’ loop to add all the integers between 0 and 50 and
display the total.
*/
$y = 0; //variable y is used to hold the previous number and then add the current number to y to
update it.
For ($x = 0; $x <= 50; $x++) { // for loop to count the numbers from 0 to 50
//echo “x number is: $x and y number is: $y \n”; //to check the values
$y+=$x; // or you can simply use $y = $y + $x; // add the new number x to update the previous number y
Screenshot:
Return 0;
;if ($flag == 1)
Else
//end php