Write a program in assembly language for x86 Processors, that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula:
Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n -1) + Fib(n - 2)
1). ANSWER :
GIVENTHAT :
#include<iostream>
using namespace std;
void printFibonacci(int n){
static int n1=0, n2=1, n3;
if(n>0){
// finding n3 by adding n1 and n2
n3 = n1 + n2;
// replacing n1 with n2
n1 = n2;
// replace n2 with n3
n2 = n3;
cout<<n3<<" ";
printFibonacci(n-1);
}
}
int main(){
int n=7;
cout<<"Fibonacci Series: ";
cout<<"0 "<<"1 ";
printFibonacci(n-2); //n-2 because 2 numbers are already
printed
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.