Problem Set
Problem Set
Fundamental Algorithms:
6. Construct a Python program to find the sum of the following series:
1 1 1 1 1 1 1 1 1
𝑠
+ 𝑠+ 𝑠+ 𝑠+ 𝑠+ 𝑠+ 𝑠+ 𝑠+ 𝑠…
2 3 5 7 11 13 17 19 23
The program needs two values n and s as input, n defines number of terms in the series and s can be
either integer or float value.
7. Construct a python program to swap the given two number using arithmetic and bitwise operators.
8. Consider your roll number as a input, Construct a python program to print True if the binary
representation of the given roll number is palindrome. Else, print False.
9. Construct an algorithm and python program to calculate sum of the following series
𝑎. 𝑥 𝑛 + 𝑎2 . 𝑥 (𝑛−1) + 𝑎3 . 𝑥 (𝑛−2) + ⋯ + 𝑎𝑛 . 𝑥 (𝑛−(𝑛−1))
10. Construct a python program to solve given problem: Consider your roll number as input, find the average
of the digits in the given number. If average is even, rotate your roll number to right direction as last digit
number of times. Else, rotate your roll number to the left direction as first digit number of times.
Factoring methods:
11. Construct a flowchart and Python program to read two number b and P from the user and then compute
the value of 𝒃𝒑 in lesser than p multiplications. Demonstrate the steps of your program for the values of
b=5 and p=99.
12. Construct a user defined Python function to calculate the square root of the given number without using
any predefined functions and power operator. Count the number of function calls initiated for the input
value 25.
13. Construct a Python program to find the non-prime factors of the given number. Illustrate the number of
steps required to compute the non-prime factors of the number n.
14. Construct a recursive Python function to find the 𝒏𝒕𝒉 Fibonacci number. Demonstrate the steps of your
python function for the input value 9 and count the number of function calls.
15. A) which of the following expressions will help us to extract third-to-last digit and second-to-last digit:
i. number % 10 %10
ii. number //10 //10
iii. number – number //10
iv. (number %100) // 10
v. number %10
vi. (numver%1000)//100
B) Illustrate the output of the following code snippet for the given inputs:
def recu_fun(n): Inputs:
if n<0: i) n=8
return recu_fun(-n) ii) n = -513
elif n<10: iii) n = 3052
return n iv) n = 74
else:
return n%10+recu_fun(n//10)