123 E E E cMP 120LIntroduction to Computer Science I Wsine f
1-2-3
Solution
Please find the anwser for the Fibonacci sequence.
Both the Fibonacci numbers as well as Fibonacci sequence are same.
Fibonacci sequence has got his name after LEONARDO FIBONACCI. 0&1 are the starting number of the Fibonacci series.. Mainly the subsequent number takes as the sum of its previous two numbers.
For Example: 0,1,1,2,3,5,8...
Here the first two numbers in the sequenceare 0 and 1. Then from the third numjber which is 1 (it is the sum of the previous two numbers), then the fourth number is the sum of the previous two numbers.
So, the mathematical representation will be
Fn=F(n-1)+F(n-2) where F0 = 1,F1,=1
#include<iostream>// lib files are added
using namespace std;
int fibo(int);// new class declaration
int main(void) // main class declaration
{
int count;// declaration
char waitInput; // declaration
cout<<\"how many numbers in the fibno series is needed \\\\ instruction for the user in the output screen
cin>> count; the input given by user will be stored in the count variable
for(int i=0;i<count;i++)
{
cout<<\" \" <<fibonacci(i)<<\" \";
}
cin>> waitInput;
return 0;
// below is the call function
int fibno (int num)
{
if(num==1) \\\\if the num is equal to 1
{
return 1; \\\\the return number will be 1
}
else if(num==0)
{
return 0;
}
else
{
return fibno(num-1)+fibno(num)
}
}
