Computer Science, asked by sandhyagkpshah6890, 1 year ago

Write an algorithm that generates the fibonacci series as: 1,1,2,3, 5,…. N terms.

Answers

Answered by aalaparunp66okp
0

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int n,terms,first,second,third;

cout<<"Enter the no.of terms : ";

cin>>n;

if(n==0)

 cout<<"Not valid ! ";

if(n==1)

 cout<<'\n'<<0<<'\t';

if(n==2)

 cout<<'\n'<<0<<'\t'<<1<<'\t';

if(n>2)

{

 first=0;

 second=1;

 cout<<'\n'<<first<<'\t'<<second<<'\t';

 for(terms=3;terms<=n;terms++)

 {

  third=first+second;

  cout<<third<<'\t';

  first=second;

  second=third;

 }

}

cout<<'\n';

getch();

}

Similar questions