summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--c/difference-of-squares/src/difference_of_squares.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/c/difference-of-squares/src/difference_of_squares.c b/c/difference-of-squares/src/difference_of_squares.c
index 0d9b6b2..f59e92c 100644
--- a/c/difference-of-squares/src/difference_of_squares.c
+++ b/c/difference-of-squares/src/difference_of_squares.c
@@ -1,17 +1,18 @@
 #include "difference_of_squares.h"
+#include <math.h>
 
 unsigned int sum_of_squares(unsigned int number) {
     unsigned int sum = 0;
-    for (unsigned int idx = 1; idx <= number; idx++)
-        sum += (idx * idx);
+    for (; number > 0; number--)
+        sum += pow(number, 2);
     return sum;
 }
 
 unsigned int square_of_sum(unsigned int number) {
     unsigned int sum = 0;
-    for (unsigned int idx = 1; idx <= number; idx++)
-        sum += idx;
-    return sum * sum;
+    for (; number > 0; number--)
+        sum += number;
+    return pow(sum, 2);
 }
 
 unsigned int difference_of_squares(unsigned int number) {