diff options
author | mjfernez <mjfernez@gmail.com> | 2020-02-09 15:16:26 -0500 |
---|---|---|
committer | mjfernez <mjfernez@gmail.com> | 2020-02-09 15:16:26 -0500 |
commit | 93ea7fe5957b62f18e8fbd17a21696bd7de6332d (patch) | |
tree | d90aed60d687bcf195f1150777f37cbe8a149814 /fib.c | |
parent | 125ec5bc3d8bfc224b7d32bcfbbc37b9fb5d441f (diff) | |
download | Project_Euler_Solutions-93ea7fe5957b62f18e8fbd17a21696bd7de6332d.tar.gz |
Organized everything, update README
Diffstat (limited to 'fib.c')
-rw-r--r-- | fib.c | 33 |
1 files changed, 0 insertions, 33 deletions
@@ -1,33 +0,0 @@ -#include <stdlib.h> -#include <stdio.h> -#include <math.h> - -const long int MAX = 4 * pow(10, 6); -int *fib; - -int main(){ - // Intialize sequence with first two terms - fib = (int *) malloc (2 * sizeof(int)); - fib[0] = 1; - fib[1] = 1; - - // loop counter - int k = 1; - // sum of even terms - int sum = 0; - //next term in sequence - int next; - while(1){ - next = fib[k] + fib[k - 1]; - printf("%d\n", next); - if(next > MAX) - break; - if(next % 2 == 0) - sum += next; - k++; - fib = (int *) realloc (fib, (k + 1) * sizeof(int)); - fib[k] = next; - } - printf("The sum of the even terms is %d\n", sum); - return 0; -} |