Skip navigation

Also very simple problem, got it on the first try with very little processing time:

int main (int argc, char * const argv[]) {
    int answer = 0;
    int value = 0;
    int cur = 1;
    int prev = 1;
    int limit;
    std::cout << "Provide a upper limit for which you would like to get the sum of even terms in the Fibonacci sequence: \n";
    std::cin >> limit;
    while(cur < limit){
      value = cur + prev;
      if(!(value % 2)){
        answer += value;
      prev = cur;
      cur = value;
    std::printf("Limit: %d Answer: %d\n", limit, answer);
    return 0;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: