Question

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By startin...

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.Place your answer in R0 at the end of your program. Can you tell me what is the reason when done debug it says running with size limit :32K .i am using Keil uVision 5. Please help me to solve this problem.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#include <stdio.h>

int main()

{

int n1 = 1, n2 = 2, temp;

long int sum = 2;

while (sum <= 4000000) {

temp = n1 + n2;

n1 = n2;

n2 = temp;

if(n2 % 2 == 0) {

sum += n2;

}

}

printf("%ld\n", sum);

return 0;

}

OUTPUT

4613732

PROCESS FINISHED WITH EXIT CODE 0.

Add a comment
Know the answer?
Add Answer to:
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By startin...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Fibonnaci sequence is a recursive sequence defined as: f0 = 1, f1 = 1, and...

    The Fibonnaci sequence is a recursive sequence defined as: f0 = 1, f1 = 1, and fn = fn−1 + fn−2 for n > 1 So the first few terms are 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, . . .. Write a function/procedure/algorithm that computes the sum of all even-valued Fibonnaci terms less than or equal to some positive integer k. For example the sum of all even-valued Fibonnaci terms less than or equal to 40...

  • 1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers...

    1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers of 1 through 15. Display your result back to the user with 2 decimal places (yes, 2 decimal places). You must implement your code using a for loop. The result should have the following format: The multiplication of 10*1 =10.00 The multiplication of 10*2 =20.00 The multiplication of 10'3=30.00 The multiplication of 10*15=150.00 2. (35 Points) Write MATLAB code to prompt a user for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT