exercism/c/difference-of-squares/difference_of_squares.c

26 lines
476 B
C
Raw Permalink Normal View History

2024-06-08 19:57:33 -04:00
#include "difference_of_squares.h"
unsigned int sum_of_squares(unsigned int number) {
unsigned sum = 0;
for (unsigned i = 1; i <= number; i++) {
sum += i * i;
}
return sum;
}
unsigned int square_of_sum(unsigned int number) {
unsigned square = 0;
for (unsigned i = 1; i <= number; i++) {
square += i;
}
return square * square;
}
unsigned int difference_of_squares(unsigned int number) {
return square_of_sum(number) - sum_of_squares(number);
}