-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path006.cs
More file actions
50 lines (41 loc) · 1.19 KB
/
Copy path006.cs
File metadata and controls
50 lines (41 loc) · 1.19 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Sum square difference
//Problem 6
//The sum of the squares of the first ten natural numbers is,
//12 + 22 + ... + 102 = 385
//The square of the sum of the first ten natural numbers is,
//(1 + 2 + ... + 10)2 = 552 = 3025
//Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
//Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
namespace _006
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(squareOfSum(100) - sumOfSquares(100));
}
static int squareOfSum(int count)
{
int sum = 0;
for (int x = 1; x <= count; x++)
{
sum += x;
}
return sum * sum;
}
static int sumOfSquares(int count)
{
int sum = 0;
for (int x = 1; x <= count; x++)
{
sum += (x * x);
}
return sum;
}
}
}