Permalink
Browse files

Add a solution to EP6 in PHP

  • Loading branch information...
1 parent a6a53e8 commit cf87a5562f355cd7617c51d5e8ab154c95b425d4 @leto leto committed Feb 15, 2014
Showing with 20 additions and 0 deletions.
  1. +20 −0 php/006/01.php
View
20 php/006/01.php
@@ -0,0 +1,20 @@
+<?
+ $n = $argv[1];
+
+ if ($n == '') {
+ $n = 100;
+ }
+
+ $sum_of_squares = 0;
+ $square_of_sum = 0;
+
+ for ( $i = 1; $i <= $n; $i++ ) {
+ $sum_of_squares += $i*$i;
+ }
+
+ $square_of_sum = pow(($n * ($n+1) / 2),2);
+
+ $diff = abs($sum_of_squares - $square_of_sum);
+
+ printf("%d\n", $diff);
+?>

0 comments on commit cf87a55

Please sign in to comment.