user enters NUMBER
for loop counting X from NUMBER to 1 counting backwards
if ( (NUMBER % X) == 0 ) then X is a factor
print X to the screen
continue looping
In the above algorithm, we use modular division. (e.g. number % x = number mod x) What modular division does, is it gives you the remainder when regular division is performed. Take the following example.
NUMBER = 12
x = 12
12/12=1
12%12=0
12 is a factor
x = 11
12/11=...
12%11=.....
11 is not a factor
.
.
.
x= 6
12/6=2
12%6=0
6 is a factor
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
Online 13,645 posts
since Feb 2002