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

25 lines
476 B
C

#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);
}