-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem006.c
36 lines (30 loc) · 862 Bytes
/
Problem006.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
/**
* Author: Austin Derrow-Pinion
* Purpose: Solve Problem 6 on Project Euler
* Language: C
*
* Finds the difference between the sum of the squares of
* the first n natural numbers and the square of the sum.
*/
long sumOfSquare(long n) {
long output = 1, i;
for (i = 2; i <= n; i++) {
output += i * i;
}
return output;
}
long squareOfSum(long n) {
long output = 1, i;
for (i = 2; i <= n; i++) {
output += i;
}
return output * output;
}
int main() {
long result = squareOfSum(10) - sumOfSquare(10);
printf("The difference between the sum of the squares of the first ten natural numbers and square of the sum is %d\n", result);
result = squareOfSum(100) - sumOfSquare(100);
printf("The difference between the sum of the squares of the first one hundred natural numbers and square of the sum is %d\n", result);
return 0;
}