Solution: Prime Factor

Look at the solution to the previous challenge.

Problem statement

Prime factors are the combinations of the smallest prime numbers that, when multiplied together, will produce the original number. Consider the following examples:

  • Prime factors of 44 are: 222 * 2

  • Prime factors of 77 are: 77

  • Prime factors of 3030 are: 5325 * 3 * 2

  • Prime factors of 4040 are: 52225 * 2 * 2 * 2

  • Prime factors of 5050 are: 5525 * 5 * 2

Implement your solution in three projects created for you:

  1. A class library in the PrimeFactorsLib project with a static class and static method named PrimeFactors that, when passed an int variable as a parameter returns a string showing its prime factors.

  2. A unit test in the unit test project named PrimeFactorsTests with a few suitable unit tests.

  3. A console application to use in the PrimeFactorsApp project.

To keep it simple, assume that the largest number entered will be 1,000.

Step-by-step solution

Let’s look at our solution by comprehensively understanding it.

Let’s have a look at Program.cs file:

Get hands-on with 1400+ tech skills courses.