From ffaacf5fdaf6a7f3fe393fd0827631b259a00b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Thu, 31 Dec 2015 15:24:44 +0100 Subject: [PATCH] Create bruteforce.c --- Project-Euler/002/bruteforce.c | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Project-Euler/002/bruteforce.c diff --git a/Project-Euler/002/bruteforce.c b/Project-Euler/002/bruteforce.c new file mode 100644 index 0000000..c99e950 --- /dev/null +++ b/Project-Euler/002/bruteforce.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +// Use: +// bruteforce +// n numbers to calculate (PE 1) +// number #1 to calculate (PE 4000000) +// number #2 to calculate +// ... +// number n to calculate + +int main() { + int n; + scanf("%d",&n); + long arr[n]; + for(int i = 0; i < n; i++){ + scanf("%li",&arr[i]); + } + + for (int i = 0; i < n; i++) + { + long sum = 2; + int a = 1, b = 2; + while (1) + { + int c = a + b; + a = b; + b = c; + if (b > arr[i]) + break; + if (b % 2 == 0) + { + sum += b; + } + } + printf("%li\n", sum); + } + +}