No need to store lots of things for just addition I remember when I first started, I put the Fibonacci series in an array and then traversed through them to add them all up. Ahhhh good times.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a = 1, b = 2;
int c, total = 2;
while (c <= 4000000){
c = a + b;
a = b;
b = c;
if (!(c % 2))
total += c;
}
printf("%d\n", total);
}
Answer:
No comments:
Post a Comment