#include <iostream>
#include <stdlib.h>
using namespace std;
bool primos(int primo);
int divs(int num);
int dato, d2;
int main()
{
cout<<divs(5);
cout<<divs(15);
THe console returns 50, which is weird since it should output 53, the first prime factor it finds for each number.
return 0;
}
// PRIMOS
bool primos(int primo)
{
int x;
for (int i = 1; i <= primo; i++)
{
if (primo % i == 0)
{
// cout << i << endl;
x += i;
}
}
if (x == (primo + 1))
{
return true;
}
return false;
}
// DIVISOR PRIMO
int divs(int num)
{
/* RETURN PRIME FACTOR */
for (int i = 2; i <= num; i++)
{
if (num % i == 0 && primos(i))
{
return i;
}
}
return 0;
}
In the main funciton, after the first iteration of the function, it no longer recognizes numbers as divisors and goes trough all of them and returns 0 (error, in this case.)