Find us on Facebook

Thursday, December 13, 2018

Fibonacci sequence



Aim: Implement a program to find the Fibonacci sequence up to n-th term where n is provided by the user.
Algorithm:
1: Start
2: set a=0,b=1,c=0,i=1
3:Input value for n
4:print a,b
5: if i<=n   go to step6 else go to step 10
6:c=a+b
7:print c
8:a=b,b=c,i=i+1
9:repeat step 5
10:stop

Program:
# Program to display
# take input from the user
nterms = int(input("How many terms? "))
# first two terms
a = 0
b = 1
c=0
print a,b
for i in range  (2,n-1):
            c=a+b
            a=b
            b=c
            print c
           
  
       Output:
How many terms? 10
Fibonacci sequence:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34,

0 Comments:

Popular Posts

Text Widget

Search This Blog

Powered by Blogger.

Blogger Pages

Like Canvas?

Sponsor

Footer Widgetized Areas

About Canvas

About Canvas

Subscribe Us

About

Text Widget

Tags

Total Pageviews

print pdf

cal

Most Popular

    TUPLES
 LIST and SLICING
      ASCII VALUE
Copyright © KTU Btech Cse Python Lab Manuals | Powered by Blogger
Design by Saeed Salam | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates