Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <stdio.h> int main(void) { int userinput; int fib3, fib1 = 1, fib2 = 1;

ID: 3650804 • Letter: #

Question

#include <stdio.h>

int main(void)
{
int userinput;
int fib3, fib1 = 1, fib2 = 1;

printf("Enter a limit on the largest number to be displayed: ");
scanf("%d",&userinput);
printf("%d ",fib1);

do
{
printf("%d ",fib2);
fib3 = fib1 + fib2;
fib1 = fib2;
fib2 = fib3;
} while(fib3 <= userinput);

return 0;

}
Write a program to find and print a Fibonacci sequence of numbers. The Fibonacci sequence is
defined as follows:

Fn = Fn-2 + Fn-1,n >= 2,where F0 = 0,F1 = 1

Your program should prompt the user to enter a limit, print the sequence up to the limit, and then
indicate what is the greatest power of 2 that the final number printed is divisible by. Note: You
are NOT allowed to use the divide function.

Here is what the user will see when the program is executed:

This program prints the Fibonacci sequence

Enter a limit on the largest number to be displayed:

Explanation / Answer

//A simple for loop, guessing you are trying to figure out how many bits it use? int i=0, a=1; for(i=0,a=Fn;a>0;i++){ a/=2; } //i is number of times divided until 0