1) What does f(31415927) return, for the following function definition?

```def f(x):
d=0
while x > 1:
(x,d) = (x/2,d+1)
return(d)```
```Answer(s) : 25
```

2) What is the value of h(6,8) for the function below?

```def h(m,n):
ans = 1
while (n > 0):
(ans,n) = (ans*m,n-2)
return(ans)```
```Answer(s) :  1296
```

3)

```def h(n):
f = 0
for i in range(1,n+1):
if n%i == 0:
f = f + 1
return(f == 2)
```

The function h(n) given above returns True for a positive number n whenever:

(A) n is a multiple of 2
(B) n is a composite number
(C) n is a prime number
(D) n has an even number of factors

```Answer(s) : (C) n is a prime number
```

4) Consider the following function f

```def f(m):
if m == 0:
return(1)
else:
return(m*f(m-1))
```

(A) The function always terminates with f(n) = n
(B) The function always terminates with f(n) = factorial of n
(C) The function terminates for non-negative n with f(n) = n
(D) The function terminates for non-negative n with f(n) = factorial of n

```Answer(s) :  (D) The function terminates for non-negative n with f(n) = factorial of n
```
Categories: NPTEL solution