0% found this document useful (0 votes)
8 views6 pages

Recursive Functions for Math Problems

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

Recursive Functions for Math Problems

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

Recursion Practice Assignment

Part - 2

Que 1. Write a recursive function findFactors() that


takes an integer n and returns all its factors (including
1 and the number itself).
Example
Input: n = 12
Output: The factors of 12 are: 1, 2, 3, 4, 6, 12

Que 2. Write a recursive function


findPrimeFactorization() that takes an integer n and
returns all prime factors of n.
Example
Input: n = 60
Output: Prime factors of 60 are: 2, 2, 3, 5

Note: Prime Factorization means breaking any number into


the form of multiplication of prime numbers only.
Que 3. Write a recursive function
findUniquePrimeFactorization() that takes an integer n and
returns unique prime factors of n.

Example
Input: n = 60
Output: Unique prime factors of 60 are: 2, 3, 5

Que 4. Write a recursive function hcf() to find the HCF


(Highest Common Factor) or GCD (Greatest Common
Divisor) of two numbers.
Example
Input: num1=36 , num2=60
Output: 12

Que 5. Write a recursive function lcm() to find the LCM (Least


Common Multiple) of two numbers.
Example
Input: num1=15 , num2=20
Output: 60

Que 6. Write a recursive function sumOddNumbers()


to find the sum of the first N odd numbers.
Example
Input: 3
Output: 9 (because 1+3+5=9)

Que 7. Write a recursive function decimalToBinary() to


convert a decimal number to its binary equivalent.
Example
Input: 5
Output: 101
Que 8. Write a recursive function nthTerm() to find the Nth
term of an arithmetic progression.
Example
Input: 3, 2, 5 (starting term = 3, common difference =
2, nth term = 5)
Output: 11 (The terms of the progression are 3, 5, 7, 9, 11)

Que 9. Write a recursive function reverseNumber()


that reverses the digits of a given integer number and
returns the reversed number.
Example
Input: 123
Output: 321

Que 10. Write a recursive function isPalindrome() that


checks whether a given integer number is a
palindrome.
Example
Input1: 12321 Input2: 87348
Output1: true Output2: false

Que 11. Write a recursive function isArmstrong()


that checks whether a given integer number is an
Armstrong number.
Example
Input: 371
(3^3+7^3+1^3 = 27+343+1 = 371)

Output : true

Que 12. Write a recursive function fibonacci() that


calculates the Fibonacci series up to the Nth term and
prints the sequence.
Example
Input: 4
Output: 0 1 1 2

Que 13. Write a recursive function perfect() to check


whether the given integer is a perfect number or not.
Example
Input: 6
1+2+3 = 6
Output: 6 is a perfect number

You might also like