summary refs log tree commit diff stats
path: root/c/difference-of-squares/src
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-08-11 15:26:15 +0530
committerAndinus <andinus@nand.sh>2021-08-11 15:26:15 +0530
commit321825828ac918bad28d0597a8616c6dc9802c3c (patch)
tree0b8e9cb1012197750eb58e972736319b2a6abac2 /c/difference-of-squares/src
parent2979ef790ac5b8f58495e0dd08cafd6a3a2e30a5 (diff)
downloadexercism-321825828ac918bad28d0597a8616c6dc9802c3c.tar.gz
Add solved exercises
Diffstat (limited to 'c/difference-of-squares/src')
-rw-r--r--c/difference-of-squares/src/difference_of_squares.c19
-rw-r--r--c/difference-of-squares/src/difference_of_squares.h8
2 files changed, 27 insertions, 0 deletions
diff --git a/c/difference-of-squares/src/difference_of_squares.c b/c/difference-of-squares/src/difference_of_squares.c
new file mode 100644
index 0000000..0d9b6b2
--- /dev/null
+++ b/c/difference-of-squares/src/difference_of_squares.c
@@ -0,0 +1,19 @@
+#include "difference_of_squares.h"
+
+unsigned int sum_of_squares(unsigned int number) {
+    unsigned int sum = 0;
+    for (unsigned int idx = 1; idx <= number; idx++)
+        sum += (idx * idx);
+    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;
+}
+
+unsigned int difference_of_squares(unsigned int number) {
+    return square_of_sum(number) - sum_of_squares(number);
+}
diff --git a/c/difference-of-squares/src/difference_of_squares.h b/c/difference-of-squares/src/difference_of_squares.h
new file mode 100644
index 0000000..cbb65f2
--- /dev/null
+++ b/c/difference-of-squares/src/difference_of_squares.h
@@ -0,0 +1,8 @@
+#ifndef DIFFERENCE_OF_SQUARES_H
+#define DIFFERENCE_OF_SQUARES_H
+
+unsigned int sum_of_squares(unsigned int number);
+unsigned int square_of_sum(unsigned int number);
+unsigned int difference_of_squares(unsigned int number);
+
+#endif
ckground-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Compatible with ranger 1.5.3 through 1.7.*
#
# Change the prompt when you open a shell from inside ranger
#
# Add this line to your .bashrc for it to work.

[ -n "$RANGER_LEVEL" ] && PS1="$PS1"'(in ranger) '