Thread: Largest prime factor and number of prime factors for a number

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    7

    Unhappy Largest prime factor and number of prime factors for a number

    Hi guys... i need some help getting the following code to display how many prime factors there are for a number (in this case the number is represented by a) and also the largest prime factor of that same number. At the moment, it displays all of the prime factors. Any help would be great.


    Code:
        for(p1 = 1; p1 <= a; p1++)
         {
               for(p2 = (a / 2); p2 > 0; p2--) 
                {
                      if (p1 * p2 == a)
                      {
                             cout << p2 << endl;
                                }
                        }
                        }
    Last edited by Jas11; 03-29-2005 at 07:11 AM.

Popular pages Recent additions subscribe to a feed