The assignment is not to find prime factors, as the OP's first post makes clear.
I have to write a program that will show all factors of a number after the input. Ex. if the user enters 8 the program will output 4 and 2.
I didn't know 4 was prime.
Here's a method, crude I know. It mimics what you might do if asked to do this with a pencil and paper, often a good starting point for finding an algorithm. Which you can later refine or discard.
Given an input number N, start at 2 (since 1 is not desired in the results) and multiply 2 by all numbers between itself and N-1, storing in an array all those where the product is N. Then do the same with 3,4,5, etc until N-1 (since N is not desired in the results) is reached.
Here it is in BASIC, I whipped this up in a hurry... I used longints in case somebody input a big number, although you could wait a long time for the answer... 9978 took 6 seconds on my 3 GHz Pentium 4. I'm still waiting for the answer to 98763, which started 6 minutes ago... But I have to go to work... Compiled in FreeBasic.
[Edit]
S:\Test\Basic\factors>factors4
number ?98763
started at 08:02:17
ended at 08:11:26
3 7 21 4703 14109 32921There are various ways you could make this more efficient...
dim N as longint
dim i as longint
dim j as longint
dim product as longint
input "number ?", N
dim array(1 to N) as longint
for element=1 to N
array(element)=0
next element
for i = 2 to N-1
for j = 2 to N-1
product=j*i
if product=N then
array(j)=1
array(i)=1
endif
next j
next i
for element=1 to N
if array(element)=1 then
print element;" ";
endif
next element
print
S:\Test\Basic\factors>factors3
number ?12
2 3 4 6
S:\Test\Basic\factors>factors3
number ?72
2 3 4 6 8 9 12 18 24 36
S:\Test\Basic\factors>factors3
number ?365
5 73
S:\Test\Basic\factors>factors3
number ?9978
2 3 6 1663 3326 4989
S:\Test\Basic\factors>