In this program, we will code to display the Fibonacci series up to number n. A Fibonacci series is a sequence starts from 0 and the next number is the sum of the previous number and the current one. For example, 0,1, 1, 2, 3, 5, 8……. Is a Fibonacci series.
C++ Program to Display Fibonacci Series
#include<iostream.h>
#include< conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
clrscr();
int f=1, n,t,s=0;
cout<<"How many numbers you want: ";
cin>>n;
for(int i=2; i<n;i++){
t = f+s;
cout<<t<<" " ;
f=s;
s= t;
}
getch();
}
Output:
How many numbers you want: 8
0 1 1 2 3 5 8
Python Program to Display Fibonacci Series
n = int(input("How many numbers you want: "))
f,s =1,0
print("0",end=" ")
for i in range(2,n):
t=f+s
print(t,end=" ")
f=s
s=t
Output:
How many numbers you want: 19
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
People are also reading:
- WAP to create a loading bar
- Python Program to Shuffle a Deck of Cards
- WAP to Print the Following Triangle
- Python Program to Find HCF or GCD
- WAP to Print the Following Pattern
- Python Program to Convert Celsius To Fahrenheit
- WAP to calculate sum and average of three numbers
- Python Program to Generate a Random Number
- WAP to find quotient and remainder of two numbers
- Python Program to Add Two Numbers
Leave a Comment on this Post