0% found this document useful (0 votes)
11 views1 page

Aryan Recur, Normal, HCF and Recur HCF

The document contains code for recursively calculating Fibonacci numbers and greatest common divisor (GCD) functions.

Uploaded by

ARYAN RATHORE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Aryan Recur, Normal, HCF and Recur HCF

The document contains code for recursively calculating Fibonacci numbers and greatest common divisor (GCD) functions.

Uploaded by

ARYAN RATHORE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

def recur_fibo(n):

if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))

nterms=15
if nterms <= 0:
print("Plese enter a positive integer")
else:
print("Fibonacci sequence:")
for i in range(1,nterms+1):
print(recur_fibo(i))

or

def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
for i in range(1,16):
print(recur_fibo(i))

#hcf
def gcd(n,x):
if x > n:
smaller = n
else:
smaller = x
for i in range(1, smaller+1):
if((n % i == 0) and (x % i == 0)):
hcf = i
return hcf
gcd(5,10)
or

def gcd(a,b):
if(b==0):
return a
else:
return gcd(b,a%b)
a=int(input("Enter first number:"))
b=int(input("Enter second number:"))
GCD=gcd(a,b)
print("GCD is: ")

print(GCD)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy