# prime numbers, counters, help!

Printable View

• 03-10-2003
vege^
prime numbers, counters, help!
Hi, I'm having a little trouble with a program I was assigned. Basically, the program has to ask for a number and produce a table that indicates the prime factorization of the number's absolute value.

For example, if the user enters the number 245, the program has to do:
Number is: 245
Sign is: +
Prime factorization of 245 is:

PRIME FACTOR | POWER
===========| =======
5 | 1
7 | 2

the professor gives us this pseudocode as a guide:

1. Repeat for k = 2,3,...,n
a. Determine if k is prime
b. if (k is prime) then
1. Determine the maximum value of d such that k^d is a factor (divisor) of [i]n[/n]
2. if (d > 0) then
k is a prime factor of n
d is the exponent

He says that's the hard pard of the proyect

Im not asking for a complete program, i just want ideas on how to calculate prime numbers, and, if possible the Prime Factor part of the table :/
• 03-10-2003
ygfperson
I want to help you out here, but the only way I could easily show you would be through code, and I don't want to give the answer away. It will become easier for you over time.

Just remember this as the basis of the whole program: For any variable x, y is a factor of x when:
x % y == 0