Given a number N, the task is to print all the factors of N using recursion.
Input: N = 16
Output: 1 2 4 8 16
1, 2, 4, 8, 16 are the factors of 16. A factor is a number which divides the number completely.
Input: N = 8
Output: 1 2 4 8
Approach: The idea is to create a function that takes 2 arguments. The function is recursively called from 1 to N and in every call, if the number is a factor of N, then it is printed. The recursion will stop when the number exceeds N.
Below is the implementation of the above approach:
1 2 4 8 16
Time Complexity: O(N)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find number of factors of N when location of its two factors whose product is N is given
- Find product of all elements at indexes which are factors of M for all possible sorted subsequences of length M
- Generating all possible Subsequences using Recursion
- Move all occurence of letter 'x' from the string s to the end using Recursion
- Program for length of a string using recursion
- Program to check if an array is palindrome or not using Recursion
- C++ Program to print an Array using Recursion
- Sum of Factors of a Number using Prime Factorization
- Decimal to Binary using recursion and without using power operator
- Find the value of ln(N!) using Recursion
- Find the node with maximum value in a Binary Search Tree using recursion
- Find Maximum Level Sum in Binary Tree using Recursion
- Find geometric sum of the series using recursion
- Decimal to binary number using recursion
- Sum of digit of a number using recursion
- Count Set-bits of number using Recursion
- Add the given digit to a number stored in a linked list using recursion
- Count the occurrence of digit K in a given number N using Recursion
- How to solve problems related to Number-Digits using Recursion?
- Print all combinations of factors (Ways to factorize)
Improved By : Rajput-Ji