diff options
author | Andinus <andinus@nand.sh> | 2021-08-11 15:26:15 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2021-08-11 15:26:15 +0530 |
commit | 321825828ac918bad28d0597a8616c6dc9802c3c (patch) | |
tree | 0b8e9cb1012197750eb58e972736319b2a6abac2 /c/difference-of-squares/src | |
parent | 2979ef790ac5b8f58495e0dd08cafd6a3a2e30a5 (diff) | |
download | exercism-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.c | 19 | ||||
-rw-r--r-- | c/difference-of-squares/src/difference_of_squares.h | 8 |
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 |