Write an Assembly program using the software Pep8 that reads an integer and then
ID: 3567748 • Letter: W
Question
Write an Assembly program using the software Pep8 that reads an integer and then stores all Fibonacci numbers from 0 to the integer entered (including that) into an array of integers of maximum size 50. Once all numbers have been stored, print them and then read an integer and display it's index in the array if it's one of the series or print "Not in series", if not. To search for the number, use binary search on the array elements.
The following is the C++ program for binary search:
int vector[50];
//populate array with Fibonacci numbers up to the limit
int first = 0, last = size - 1, mid = (first + last) / 2; where size is the number of integers stored in the array
while(first <= last)
{
if(value < nums[mid]) //if value < middle value
{
last = mid - 1;
mid = (first + last) / 2;
}
else if(value > nums[mid])
{
first = mid + 1;
mid = (first + last) / 2;
}
else
{
cout << " Value found at index " << mid;
//return
}
}
cout << " Value is not part of the series.";
//return
Example:
Enter limit: 150
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 134
Enter number: 89
89 found at index 11.
Put your name on top as a comment and comment most if not all your statements. You can use C++ code for commenting your statements.
Submit the .pepo or text file.
Explanation / Answer
PROC print fibo = (INT n) VOID : # prints out the Fibonacci sequence up to n. # BEGIN INT a := 0, b := 1; FOR i TO n DO print((whole(i, 0), " => ", whole(b, 0), new line)); INT c = a + b; a := b; b := c OD END; INT i; print("Compute Fibonacci sequence up to? "); read((i, new line)); print fibo(i)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.