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)
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find number of factors of N when location of its two factors whose product is N is given
- Program to print factors of a number in pairs
- Efficient program to print the number of factors of n numbers
- C Program for efficiently print all prime factors of a given number
- Efficient program to print all prime factors of a given number
- Find sum of odd factors of a number
- Find sum of even factors of a number
- Java Program for efficiently print all prime factors of a given number
- Find minimum sum of factors of number
- Queries to find whether a number has exactly four distinct factors or not
- Check if a number exists having exactly N factors and K prime factors
- Maximum number of prime factors a number can have with exactly x factors
- Find all Factors of Large Perfect Square Natural Number in O(sqrt(sqrt(N))
- Number of factors of very large number N modulo M where M is any prime number
- Program to Calculate e^x by Recursion
- Queries on sum of odd number digit sums of all the factors of a number
- C++ Program to print an Array using Recursion
- Program for length of a string using recursion
- Program to check if an array is palindrome or not using Recursion
- Number with maximum number of prime factors
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Rajput-Ji