-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler6.cpp
More file actions
67 lines (43 loc) · 1.11 KB
/
Copy patheuler6.cpp
File metadata and controls
67 lines (43 loc) · 1.11 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// Created by Henry Glover on 8/19/23.
//
/*
*
* The sum of the squares of the first ten nat num is:
*
* 1^2 + 2^2 + 10^2 = 385
*
* the square of the sum of the first ten nat num is:
*
* (1+2+...+10)^2 = 55^2 = 3025
*
* the difference is 3025 - 385 = 2640
*
* do the same for the first 100 numbers
*
*/
#include <iostream>
int squareOfSum (int num) ;
int sumOfSquare (int num) ;
int main () {
int length = 100;
int diffNum = sumOfSquare(length) - squareOfSum(length);
std::cout << "difference of the square of the sum minus the sum of the squares is : " << diffNum << std::endl;
}
int squareOfSum (int num) {
int sqrSumTotal = 0;
for (int i = 0; i <= num; i++) {
sqrSumTotal = sqrSumTotal + (i * i);
}
std::cout << "Square of Sum : " << sqrSumTotal << std::endl;
return sqrSumTotal;
}
int sumOfSquare (int num) {
int sumSqrTotal = 0;
for (int i = 0; i <= num; i++) {
sumSqrTotal = sumSqrTotal + i;
}
sumSqrTotal = sumSqrTotal * sumSqrTotal;
std::cout << "Sum of Square : " << sumSqrTotal << std::endl;
return sumSqrTotal;
}