OOPS Lab File 2
OOPS Lab File 2
Algorithm :
• Start
• Declare variables i, a, b, c.
• Initialize the variables, a=0, b=1, and c.
• Enter the number of terms of Fibonacci series to be printed.
• Print First two terms of series.
• Use loop for Fibonacci series.
• End
Source Code :
#include<iostream>
using namespace std;
int main()
{
int a,b,c,n;
a=-1;
b=1;
cout<<"Enter number of terms in a series: ";
cin>>n;
for(int i=0;i<n;i++)
{
c=a+b;
cout<<c<<" ";
a=b;
b=c;
}
return 0;
}
Output : (SCREENSHOT)