C# solutions to Project Euler problems.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
774 B

using System;
using System.Collections.Generic;
namespace Euler {
class Program {
static int Problem1() {
int sum = 0;
for (int i = 1; i < 1000; i++) {
if (i % 3 == 0 || i % 5 == 0) {
sum += i;
}
}
return sum;
}
static long Problem2() {
int max = 4_000_000;
var fibs = new List<int>();
fibs.Add(1);
fibs.Add(2);
while (fibs[fibs.Count - 1] < max) {
int num = fibs[fibs.Count - 1] + fibs[fibs.Count - 2];
fibs.Add(num);
}
int sum = 0;
foreach (int i in fibs) {
if (i % 2 == 0 && i <= max) {
sum += i;
}
}
return sum;
}
static void Main(string[] args) {
Console.WriteLine(Problem2());
}
}
}