blob: 27311ec6efc55d817c7e76f24cb3e2c523b57cc5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include "difference_of_squares.h"
#include <math.h>
// Returns the sum of squares upto nth Natural number.
unsigned int sum_of_squares(unsigned int number) {
return (number * (number + 1) * (2 * number + 1)) / 6;
}
// Returns the square of sum upto nth Natural number.
unsigned int square_of_sum(unsigned int number) {
return pow((number * (1 + number)) / 2, 2);
}
unsigned int difference_of_squares(unsigned int number) {
return square_of_sum(number) - sum_of_squares(number);
}
|