Experiment no.
: 2 Date of Experiment :04-02-2023
Name : Ashutosh kumar chaubey Admission No.: 22SCSE1012384
Enrollment No. :22131012234
AIM : Write a C++ program to generate the first n terms of the
sequence of Fibonacci series.
Introduction : A fibonacci sequence is difined as follows the first
and second term in the sequence are 0 and 1. Subsequent terms are
found by adding the proceeding two terms in the sequence.
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)