Sei sulla pagina 1di 5

a) def compute(x,y):

if x>1:
if x%y==0:
print(y,end=’’)
compute(int(x/y),y)
else:
compute(x,y+1) // compute(3,3)
compute(24,2)
What will be the output when we call compute(24,2) and
compute(84,2)
O/P: 2 2 2 3
b) def check(m,n):
if n==1:
return –m
else:
return (m+1) + check(m+1,n-1)
check(5,5)
c) def skipprod(n):
if n==0:
return 1
else:
return n*skipprod(n-2)
d) def factorial(n):
if n==0:
return 1
else:
n*factorial(n-1)
print(factorial(4))
e) def out(n):
i=1
if i>n:
return
else:
print(i)
i+=1
out(i)
out(4)
f) def express(x,n):
if n==0:
return 1
elif n%2==0:
return express(x*x,n/2)
else:
return x*express(x,n-1)
express(2,5)
g) def check(n):
if n<=1:
return True
elif n%2==0:
return check(n/2)
else:
return check(n/1)
check(8)

h) def fn(n):
print(n,end=’’)
if n<3:
return n
else:
return (fn(n//2)-fn(n//3))
fn(10)

i) def recur(p):
if p==0:
print(“##”)
else:
recur(p)
p=p-1
recur(5)

Potrebbero piacerti anche