Factors of a Number are the whole numbers which on multiplication of them form that number. For Eg. Factor of 12 are 2,4,6,3. 2 X 6 = 12 and 4 X 3 = 12 and their vice versa.
Factors are the essential element in mathematics. It is used to solve various problems in mathematics and even in real life. To divide the elements into that factors. Like 5 $20 make $100 or even finding the average.
Try to collect as much data as we can like we are taking the factors of the number we know that by dividing them with factors they are purely divisible.We also know that the largest number divisible would be its half , so we can run the loop till half of the given digit and check its modulus with 1 to n/2 (n is the number whose factor we have to find)
Here in this algorithm we declare 2 variables as integer one for storing the number and other for running the for loop. Then we read the variable n. We run the for loop form i=0 to n/2 incrementing i by 1.Then using the if statement checking if the number n is divisible by i or not for that we use modulo operator it gives the remainder if a number n is divided by modulo of that number i .If the modulo is 0 then print i.
Our Quiz prepared by Experts Helps you identify your knowledge in Algorithms. Everyone should atleast attempt this Quiz Once.