I am going to write a program that display the fibonacci series
#include<iostream> // header file allows operate the input and output operation
using namespace std; // Standard namespace
int main(){
int i,n,n1=1,n2=0,n3; // n1 is the 1st term , n2 is the 2nd ans n3 //is 3rd term
cout<<"Enter the number of terms:"; // asking from the user //to enter the number of terms
cin>>n; // taking the number of terms from the keyboard
cout<<"Fibonacci series:\n\n";
for(i=0;i<n;i++){
n3=n1+n2;
n1=n2;
n2=n3;
cout<<n3<<" ";
}
return 0;
}
Output:-
Let's input n=12
#include<iostream> // header file allows operate the input and output operation
using namespace std; // Standard namespace
int main(){
int i,n,n1=1,n2=0,n3; // n1 is the 1st term , n2 is the 2nd ans n3 //is 3rd term
cout<<"Enter the number of terms:"; // asking from the user //to enter the number of terms
cin>>n; // taking the number of terms from the keyboard
cout<<"Fibonacci series:\n\n";
for(i=0;i<n;i++){
n3=n1+n2;
n1=n2;
n2=n3;
cout<<n3<<" ";
}
return 0;
}
Output:-
Let's input n=12
Let's input n=15
Comments
Post a Comment