Page Contents
Interview Content
- C Programming Coding Questions
- C Pattern Programming Questions
- C Programming Interview Questions
- Java Programming Coding Questions
- Java Pattern Programming Questions
- Java Programming Interview Questions
- Python Programming Coding Questions
- Python Pattern Programming Questions
- Python Programming Interview Questions
- SQL Interview Questions
Fibonacci series program in python using iterative method
Ans:
In this tutorial we are going to learn how to print Fibonacci series in Python program using iterative method.
In this series number of elements of the series is depends upon the input of users. Program will print n number of elements in a series which is given by the user as a input.
Before moving directly on the writing Fibonacci series in python program, first you should know
What is Fibonacci Series?
A Fibonacci series is a series in which next number is a sum of previous two numbers.
For example : 0, 1, 1, 2, 3, 5, 8 ……
In Fibonacci Series, first number starts with 0 and second is with 1 and then its grow like,
0
1
0 + 1 = 1
1 + 1 = 2
1 + 2 = 3
2 + 3 = 5 and
so on…
How our program will behave?
Suppose if someone gives an input 5 then our program should print first 5 numbers of the series.
Like if someone given 5 as a input then our Fibonacci series which is written in C should print output as,
0, 1, 1, 2, 3
Python program to print Fibonacci series program in using Iterative methods
first,second=0,1
n = int(input("please give a number for fibonacci series : "))
print("fibonacci series are : ")
for i in range(0,n):
if i<=1:
result=i
else:
result = first + second;
first = second;
second = result;
print(result)
Output:
Latest Uploads on Website
- AVL Tree with explanation
- Radix sort algorithm explanation with example
- Quick Sort Algorithm with explanation
- Bubble sorting algorithm with Bubble sort program in C
- Insertion sort algorithm and program in C
- Selection Sort Algorithm and Program in C
- Linear probing technique explanation with example
- Collision in Hashing and Collision resolution technique
- Hashing in data structure with its types
- Binary search tree operations with Program
- Binary search tree in data structure
- Binary search algorithm in data structure with explanation
- linear search in data structure with Algo and Program