<?php include "helper.php"; function sumOfSquares($max) { $x = 1; $sum = 0; while ($x <= $max) { $sum += $x * $x; $x++; } return $sum; } function squareOfSums($max) { $x = 1; $sum = 0; while ($x <= $max) { $sum += $x; $x++; } return $sum * $sum; } $num = 100; result(25164150, squareOfSums($num) - sumOfSquares($num));
function difference($max) { return squareOfSums($max) - sumOfSquares($max); }
public function testSumOfSquaresTo100() { $this->markTestSkipped(); $this->assertEquals(338350, sumOfSquares(100)); }
function difference($input) { return squareOfSums($input) - sumOfSquares($input); }
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum . */ $a = 1; $b = 100; function sumOfSquares($num1, $num2) { foreach (range($num1, $num2) as $number) { $squaredNumber = pow($number, 2); $total += $squaredNumber; } echo "The total of sumOfSquares is {$total}" . '<br>'; return $total; } function squareOfSum($num1, $num2) { foreach (range($num1, $num2) as $number) { $total += $number; } $grandTotal = pow($total, 2); echo "The total of square of sums is {$grandTotal}" . '<br>'; return $grandTotal; } function diffInSums($grandTotal, $total) { $superGrand = $total - $grandTotal; echo "The super grand total is {$superGrand}" . '<br>'; } //sumOfSquares(1, 10); //squareOfSum(1, 10); diffInSums(sumOfSquares($a, $b), squareOfSum($a, $b));
function difference($value) { return squareOfSums($value) - sumOfSquares($value); }