n mathematics, the Fibonacci numbers (in this case only positive numbers) are th
ID: 3733509 • Letter: N
Question
n mathematics, the Fibonacci numbers (in this case only positive numbers) are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones 011 2 3 5 8 13 21 34 55 89 144 .. . Write a function called fibonacci that takes two integers arguments and prints out in ascending order all fibonacci numbers between the first (or closest higher or equal) and the second argument (closest lower or equal). Your function must return the amount of fibonacci numbers printed out. Example 1: When the input is 34 The output is 5 8 13 21 34 The function must return 5 Example 2: When the input is 100Explanation / Answer
#include <stdio.h>
int main()
{
int t1 = 0, t2 = 1, nextTerm = 0, n, m;
// take lower limit from user
printf("Enter a lower limit number: ");
scanf("%d", &m);
// take upper limit from user
printf("Enter a upper limit number: ");
scanf("%d", &n);
// print lower and upper limit
printf("Fibonacci Series between: %d, %d ", m, n);
printf("Fibonacci Series :");
nextTerm = t1 + t2;
while(nextTerm <= n)
{
// check lower condition
if(nextTerm>=m)
printf("%d ",nextTerm);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.