Question

In: Computer Science

(a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence,...

(a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the two preceding ones: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 114, … etc. By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two. We define Fib(0)=0, Fib(1)=1, Fib(2)=1, Fib(3)=2, Fib(4)=3, etc. The first 22 Fibonacci numbers given below: Fib(0) Fib(1) Fib(2) Fib(3) Fib(4) Fib(5) Fib(6) Fib(7) Fib(8) Fib(9) Fib(10) 0 1 1 2 3 5 8 13 21 34 55 Fib(11) Fib(12) Fib(13) Fib(14) Fib(15) Fib(16) Fib(17) Fib(18) Fib(19) Fib(20) Fib(21) 89 144 233 377 610 987 1597 2584 4181 6765 10946 Write a MARIE program to calculate Fib(n), where the user inputs n. For example, if the user inputs 7, the program outputs the value 13; if the user inputs 15, the program outputs the value 610; if the user inputs 20, the program outputs the value 6765 etc. You need to write and run the program using MARIE simulator. Please include appropriate comments to make your code readable. Important:Please run the mas file in the MARIE simulator to check if it works correctly. Try inputting numbers like 0, 1, 5, 10, 22 etc. 1 mark would be deducted if the codes are not commented. (b) For some values of n, your program will not produce correct results. You can check this by gradually increasing the values of n and checking for the correct outputs. What is the maximum value of n for which your program produces a correct result? Why?

Solutions

Expert Solution

# Fibonacci Sequence Using MERIE SIMULATOR :-

ORG 100

INPUT /get input fromuser

STORE num /store the input

Cond, LOAD COUNT / Load count value

SUBT num / Remove num from count to get exact output

ADD ONE

SKIPCOND 000 / if 0 , skip

JUMP End / loop ends

Loop, LOAD COUNT

ADD ONE

STORE COUNT

JNS Fibb

JUMP Cond

Fibb, HEX 000

CLEAR / clear the accumulator

/ add f1 and f2

ADD F1   

ADD F2   

STORE Fi   

/ store f2 in f1

LOAD F2   

STORE F1  

/ store f1 in f2

LOAD Fi   

STORE F2   

/ print the output

LOAD Fi   

OUTPUT   

JUMPI Fibb

End, HALT / Halt the process

/ variables declarations

COUNT, DEC 0   

Fi, DEC 0

F1, DEC 0

F2, DEC 1

num, DEC 0/ constant values dealrations

ONE, DEC 1

OUTPUT : will be the Fibonacci Sequence  

0,0,1,2,3,5,,8,13,,21,34,55,89.... so on

Note : Please i don't have Marie compiler so i show output by written

b) For some values of n, the program is not producing appropriate results as it should behave. This abnormality is occurring due to the limit of the integers being crossed by the system. There is a limit to the value that can be stored by data type. In this case after careful analysis of the output we have seen that the output produced is correct for values of n up to n= 24. After this threshold is reached or crossed the program starts displaying results in the negative value ranges.


Related Solutions

The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are...
The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are both 1; after that, each number is the sum of the preceding two numbers. 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... For example, 1+1=2, 1+2=3, 2+3=5, 3+5=8, etc. The nth Fibonacci number is the nth number in this sequence, so for example fibonacci(1)=1, fibonacci(2)=1, fibonacci(3)=2, fibonacci(4)=3, etc. Do not use zero-based counting; fibonacci(4)is 3, not 5. Your assignment...
The Fibonacci sequence is an infinite sequence of numbers that have important consequences for theoretical mathematics...
The Fibonacci sequence is an infinite sequence of numbers that have important consequences for theoretical mathematics and applications to arrangement of flower petals, population growth of rabbits, and genetics. For each natural number n ≥ 1, the nth Fibonacci number fn is defined inductively by f1 = 1, f2 = 2, and fn+2 = fn+1 + fn (a) Compute the first 8 Fibonacci numbers f1, · · · , f8. (b) Show that for all natural numbers n, if α...
Google the first 50 numbers of the Fibonacci sequence (starting with 1) to answer the following...
Google the first 50 numbers of the Fibonacci sequence (starting with 1) to answer the following questions:          (a) Test to see if the leading digits conform to Benford’s law. Do this both graphically and analytically.          (b) Using the first 10 odd numbers in the sequence as sample 1 and the first 10 even numbers in the sequence as sample 2, use Wilcoxon’s Rank-Sum to test the claim that the numbers come from different populations.          (c) Repeat (b)...
Using C++ use dynamic programming to list first 30 Fibonacci numbers. Fibonacci sequence is famous problem...
Using C++ use dynamic programming to list first 30 Fibonacci numbers. Fibonacci sequence is famous problem solved with recursion. However, this can also be done more efficiently using dynamic programming. Create a program that uses dynamic programming techniques to list the first 30 Fibonacci numbers.
Write a c++ program of the Fibonacci Sequence. Have the user enter a positive integer n...
Write a c++ program of the Fibonacci Sequence. Have the user enter a positive integer n and compute the nth Fibonacci number. The program should end when the user enters a number less than or equal to zero
In this assignment, you will calculate and print a list of Fibonacci Numbers . Fibonacci numbers...
In this assignment, you will calculate and print a list of Fibonacci Numbers . Fibonacci 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: The sequence Fn of Fibonacci numbers is defined by the recurrence relation:  which says any Nth Fibonacci number is the sum of the (N-1) and (N-2)th Fibonacci numbers. Instructions Your task will be...
Consider the Fibonacci sequence 1,1,2,3,5,8,13,21,34,55,89,…. . The first two numbers are 1 and 1. When you...
Consider the Fibonacci sequence 1,1,2,3,5,8,13,21,34,55,89,…. . The first two numbers are 1 and 1. When you add these numbers you get 2 = 1+1, which becomes the third number in the sequence. When you add the second and third numbers, you get 3 = 1+2, which becomes the fourth number in the sequence. When you add the third and fourth numbers, you get 5 = 2+3, which becomes the fifth number in the sequence; and so on to generate the...
The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8,.... Formally,...
The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8,.... Formally, it can be expressed as: fib0 = 0 fib1 = 1 fibn = fibn-1 + fibn-2 Write a multithreaded C++ program that generates the Fibonacci series using the pthread library. This program should work as follows: The user will enter on the command line the number of Fibonacci numbers that the program will generate. The program will then create a separate thread that will...
how to find arithmetic sequence, geometric sequence, and fibonacci sequence on excel?
how to find arithmetic sequence, geometric sequence, and fibonacci sequence on excel?
( Assembly Language ) Write a program that computes the 7th fibonacci number. The fibonacci sequence...
( Assembly Language ) Write a program that computes the 7th fibonacci number. The fibonacci sequence - 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, … what is the initialization of a, b, and d? - a b d 1 ? ? 1 2 ? ? 1 3 1 1 2 4 1 2 3 5 2 3 5 6 3 5 8 7 5 8 13 wrong initialization - a b d 1 0 1 1 2...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT