Thread: problem

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    114

    problem

    Hi, I am trying to find out how to create a program which will print the prime factors of a number inputed. my code is
    Code:
    #include <iostream>
    
    using namespace std;
    
    
    int main()
    {   int x;
        cin>>x;
        int i=1;
        while(i<x)
        {
            if (x%i==0)
            {
                cout<<i<<"\n";
                x=x/i;
                 
    
    
            }
            else 
            {i++;
                      }
    
    cout<<x;
    
    
        }
    
    
    
    
    }
    is it possible to make a code that would add all this factors??
    Last edited by Tamim Ad Dari; 01-12-2013 at 08:08 AM.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    For this to work properly i needs to be a prime. You should start with a decent list of primes, if you don't want to implement a prime number test.

    Also a good compile does not mean that your program is free of logic errors. Compiling doesn't detect those.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 01-06-2013, 07:49 AM
  2. Replies: 1
    Last Post: 12-07-2012, 10:00 AM
  3. Replies: 4
    Last Post: 10-16-2008, 07:30 PM
  4. Visual Studio Linker problem or my problem?
    By OOPboredom in forum C Programming
    Replies: 2
    Last Post: 04-13-2004, 12:32 AM
  5. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 09:14 AM