Write a program that will ask a user to input a number n. The program will then display a
Fibonacci sequence with n as number of displayed sequence.
#include <iostream>
using namespace std;
int main()
{
int sum=0, n;
int a=0;
int b=1;
cout<<"Enter the nth value ";
cin>>n;
cout<<"Fibonacci series="<<endl;
while(sum <= n)
{
cout<<sum;
a = b;
b = sum;
sum = a + b;
}
return 0;
}
Comments
Leave a comment