mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-11-09 21:30:47 -05:00
25 lines
476 B
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);
|
|
}
|