[c++]A method of finding prime factors

madurax86

Member
Jun 29, 2006
4,385
88
0
Optimise/modify as you like, and oh tell me the system that you'll use too(other than this)
Code:
#include <cstdlib>
#include <iostream>

using namespace std;

long rec(long s)
{
    long i;

    if (s==0){ cout<<"0"<<endl; return 0; }
    for (i=2;i<=(s/2);i++)
    {
        if (s % i == 0)
        {   
            cout<<i<<endl;
            s=s/i;
            i=2;         
        }    
    }
    cout<<s<<endl;
}

int main()
{
    long a;
    bool t;
    char l;
    cout<<"Enter a number to find prime factors : ";
    cin>>a;
    rec(a);
    t=1;
    while (t=1)
    {
        cout<<"again? (y/n)"<<endl;
        cin>>l;
        if (l=='n') 
            {
                t=0;
                break;
            }
        else if (l=='y')
            {
                cout<<"Enter a number to find prime factors : ";
                cin>>a;
                rec(a);
            } 
    }
}
 

madurax86

Member
Jun 29, 2006
4,385
88
0
යකෝ මම කිව්වෙ Error එක handle කරපන් කියල :baffled: Again 3k එනව :rofl:
පට්ට මචන් ;):P

ආහ් අනේ ඕව කරන්න බෑ හිහි සාමාන්‍ය තත්ව යටතේ අවුලක් නැතුව වැඩ නේ