mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-11-14 07:10:48 -05:00
26 lines
476 B
C
26 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);
|
||
|
}
|