Output:

Explanation:

In this program we have implemented the very traditional method of finding the prime factors of a number, which we all used in junior classes.

When we were told to find the HCF of 2 numbers, we first used to find the Prime Factors of both the numbers separately and then used to take the common factors and multiply them for finding the HCF – Remember?

And we used to first start dividing that number by 2, then if it was divisible, we would again divide it by 2 and this would go on till it is being divided by 2, then we moved on to check its divisibility by 3, then with 5, 7 etc. We used to divide, until we reached 1, after which we used to stop.

2 | 24
2 | 12
2 | 6
3 | 3 | 1

Remember, the above method? And the Prime Factors using the above method would come as 2, 2, 2, 3 for 24.

This is the very logic being used in the above program.

1. We start dividing the number by 2, hence, the value of ‘i’ begins with 2.

2. If it is divisible, then the value of ‘i’ is printed, and the next number becomes (n/i) , like we used to have in our junior arithmetic.

3. If it is not divisible by 2, then the value of ‘i’ is incrementing.

4. And this checking goes on till the number is greater than 1, because if it becomes 1, we need to stop this process of dividing.

Check Also

Solution of Program 1 of ISC 2017 Computer Science Paper 2 (Practical) Exam. Java program to input number of boxes to be packed and display the break-up of the cartons used in descending order of capacity

ICSE | ISC Sample Papers

In this section we will be providing you with the Sample/Guess papers of ICSE (Computer Applications) and ISC (Computer Science) which can be easily downloaded. We hope that the students will benefit from these resources.