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

Note : use C languge to do this program , and when you finish convert it to Assi

ID: 3687201 • Letter: N

Question

Note : use C languge to do this program , and when you finish convert it to Assimbley languge. Thanks in advance

Write a program to find and print a Fibonacci sequence of numbers. The Fibonacci seque : nce is defined as follows Fn = Fn-2 + Fn-1, where Fo = 0 and F1-1. Your program should prompt the user to enter a limit, print the sequence up to the limit, and then indicate the greatest power of 2 that the final number printed is divisible by. Assume user input will be between 1 and 4096. 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 50 is Input 112358 13 21 34 The last number 34 is divisible by 2. Do you want to print a different sequence (Y/N): y y is Input

Explanation / Answer

#include<stdio.h>

int greatestPowerOf2(int x){
   int j=2;
   while(x%j==0){
      j = 2*j;
   }
   return j/2;
}

void fibonacci(int n){
   int first = 0, second = 1, next =0,max = 0 , c = 0;
   while (next<=n){
         if ( c <= 1 )
            next = c;
         else
         {
            max = next;
            next = first + second;
            first = second;
            second = next;
         }
         c++;
         if (next<=n){
            printf("%d ",next);
         }
   }

   printf("The last number %d is divisible by %d. " , max,greatestPowerOf2(max));
}

int main()
{
   int n;
   char c;
   int flag = 1;
   printf("This program prints the fibonacci sequence ");
   while(flag){
      printf("Enter a limit on the largest number to be displayed:");
      scanf("%d",&n);
      fibonacci(n);
      printf("Do you want to print a different sequence (Y/N):");
      scanf("%s",&c);
      if (c == 'n' || c== 'N'){
         flag = 0;
         printf("%s ", "Goodbye");
      }
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote