prime numbers, counters, help!

This is a discussion on prime numbers, counters, help! within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm having a little trouble with a program I was assigned. Basically, the program has to ask for a ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    28

    Exclamation 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 :/

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Replies: 18
    Last Post: 11-04-2005, 01:41 PM
  3. More Prime Numbers
    By mmuhlenb in forum C Programming
    Replies: 3
    Last Post: 02-21-2003, 09:06 AM
  4. Prime numbers
    By Lazy Student in forum C Programming
    Replies: 12
    Last Post: 05-14-2002, 05:53 AM
  5. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 04:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21