开发者

Calculating sum of squares in PHP [closed]

开发者 https://www.devze.com 2023-04-05 13:47 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

Write a program that accepts an integer larger than 1 and calculates the sum of the squares from 1 to that integer. For example, if the integer equals 4, the sum of the squares is 30 (1 + 4 + 9 + 16, noti开发者_如何学运维ce 4 numbers)

Help plz


$number = intval( $_GET["number"] );
$sum = 0;

for ( $i = 1; $i <= $number; $i++ ) {
    $sum += $i * $i;
}

echo $sum;

Here is the html:

<form action="mypage.php" method="GET">
   <input type="text" name="number" />
   <input type="submit" />
</form>
0

精彩评论

暂无评论...
验证码 换一张
取 消