[해결로 표시] Print and Sum - PHP Task

  

3
주제 스타터

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

1개 답글
2

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;
공유: