Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2, Sig, Sigo 3 years ago committed by GitHub
parent f2499624d7
commit 061108eb02
  1. 30
      archives/2/src/main.c
  2. BIN
      current
  3. 16
      src/main.c

@ -0,0 +1,30 @@
#include <stdio.h>
/*
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
https://projecteuler.net/problem=2
*/
int main(int argc,char**argv) {
int fibStorage[1000];
int val=0;
int counter=0;
int sum=0;
while (val<4000000) {
if (counter>2) {
val=fibStorage[counter++]=fibStorage[counter-2]+fibStorage[counter-1];
} else {
val=fibStorage[counter++]=counter;
}
printf("Fib %d is %d\n",counter,val);
if ((val&1)==0) {
sum+=val;
}
}
printf("Sum: %d",sum);
return 0;
}

Binary file not shown.

@ -10,5 +10,21 @@ By considering the terms in the Fibonacci sequence whose values do not exceed fo
https://projecteuler.net/problem=2
*/
int main(int argc,char**argv) {
int fibStorage[1000];
int val=0;
int counter=0;
int sum=0;
while (val<4000000) {
if (counter>2) {
val=fibStorage[counter++]=fibStorage[counter-2]+fibStorage[counter-1];
} else {
val=fibStorage[counter++]=counter;
}
printf("Fib %d is %d\n",counter,val);
if ((val&1)==0) {
sum+=val;
}
}
printf("Sum: %d",sum);
return 0;
}
Loading…
Cancel
Save