Example 39: Prime Factors
Learn how to calculate prime factors of a given number.
We'll cover the following...
We'll cover the following...
Problem
Write a function that takes a positive integer as input and obtains its prime factors.
Example
| Input | Output |
|---|---|
| 10 | 2 5 |
| 24 | 2 2 2 3 |
| 35 | 5 7 |
| 45 | 3 3 5 |
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.
❗Remember to print the factors in ascending order.