Monday, 27 February 2012

Fibonacci series in pyhton

#print Fibonacci series in python
#In mathematics the Fibonacci numbers are the numbers in the following interger sequense:
#0,1,1,2,3,5,8,13,21,34,55....
#logic ==>   
F_n = F_{n-1} + F_{n-2},\!\,

//programme start from here



-  def  fib(n):     #definition of function


        val1,val2=0,1
        i=0
        print(val2)
-        while i<=n:
           val3 = val1 + val2
           val1 = val2
           val2 = val3
           i=i+1
         
 print(c)


-  def main():
       val=input(" Enter the value for Fibonacci series of nth term := ")  
       fib(val)   #function call 
main()   #main programme start from here  

No comments:

Post a Comment

Compiler for C,C++ and Python {paste your programme to see the output}