Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int facts(int, int);
- bool esPrimo(const int);
- int main()
- {
- int n, m;
- cout<<"Introduce un número entero"<<endl;
- cin>>n;
- cout<<"\n\nLos factores primos de "<<n<<" en orden decreciente son:"<<endl;
- if(esPrimo(n)) cout<<n<<endl;
- m=facts(n, n/2);
- return 0;
- }
- int facts(int num, int q){
- if( q==0 ) return 0;
- if( num%q==0 && esPrimo(q) ) cout<<q<<endl;
- return facts(num, q-1);
- }
- bool esPrimo(const int num){
- if( num<0 )
- return 0;
- for(int i=2; i<=(num/2); i++)
- if( num%i==0 )
- return 0;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement