Example 47: Prime Factors of a Number

Learn how to calculate the prime factors of a given number using recursion.

Problem

Write a recursive function that takes a positive number as an input and calculates its prime factors.

Example

Input Output
3 3
42 2, 3, 7
55 5, 11

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Get hands-on with 1400+ tech skills courses.