Calculating sum of squares in PHP [closed]
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>
精彩评论