user enters NUMBER
for loop counting X from NUMBER to 1 counting backwards[indent]if ( (NUMBER % X) == 0 ) then X is a factor
print X to the screen
[/indent]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
cscgal
The Queen of DaniWeb
19,422 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230