settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Print and Sum - PHP Task (Solved)

+1 vote

Write a program to display numbers from given start to given end and their sum. All the numbers will be integers. On the first line you will receive the start number, on the second the end number.

Examples:

print and sum php task

 

asked in PHP category by user eiorgert

1 Answer

+1 vote

Here is my solution:

<?php
$start = intval(readline());
$end = intval(readline());
$result = 0;

for ($i = $start; $i <= $end; $i++) {
    echo $i . ' ';
    $result += $i;
}
echo PHP_EOL . 'Sum: ' . $result;
answered by user icabe
Great! Thanks! George
...