8. Program that inputs a number from the user and displays Fibonacci series up to the number entered.
Chapter 6:
Looping Structures
Programming Exercise
Problem # 8:
Write a program that inputs a number from the user and displays Fibonacci series up to the number entered.
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a,b, n,next,count;
cout<<"Enter the fabonacci terms required:";
cin>>n;
a=0;
b=1;
cout<<endl<<a<<"\t"<<b;
count=2;
while(count<n)
{
next=a+b;
cout<<"\t"<<next;
a=b;
b=next;
count++;
}
return 0;
}
#include<conio.h>
using namespace std;
int main()
{
int a,b, n,next,count;
cout<<"Enter the fabonacci terms required:";
cin>>n;
a=0;
b=1;
cout<<endl<<a<<"\t"<<b;
count=2;
while(count<n)
{
next=a+b;
cout<<"\t"<<next;
a=b;
b=next;
count++;
}
return 0;
}
Let me know in the comment section if you have any question.
Previous Post:
7. Program that inputs a series of 20 numbers and displays the minimum value.
Comments
Post a Comment