GNU nano 2.2.6 File: done.c #include <stdio.h> int main(void) { int userinput; i
ID: 3651146 • Letter: G
Question
GNU nano 2.2.6 File: done.c#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);
int j;
int max = 0;
int temp = fib1;
for(j = 1; j < temp; j++)
{
if(temp % j == 0 && j % 2 == 0)
max = j;
}
printf(" The last number %d is disible by %d ", temp, j);
return 0;
}
I am trying to get the loop to do the below so far i can get it to print out the correct FIB numbers but when adding the for loop it wont even do that anymore.
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: 50
1 1 2 3 5 8 13 21 34
The last number 34 is divisible by 2.
Do you want to print a different sequence (Y/N): y
Enter a limit on the largest number to be displayed: 200
1 1 2 3 5 8 13 21 34 55 89 144
The last number 144 is divisible by 16.
Do you want to print a different sequence (Y/N): n
MY OUTPUT IS:
Enter a limit on the largest number to be displayed: 50
1 1 2 3 5 8 13 21 34
The last number 34 is disible by 34
What am I doing wrong?
Explanation / Answer
int this line printf(" The last number %d is disible by %d ", temp, j) max should be there in place of j
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.