Here’s my code to find the prime factors of a number :
#include <iostream>
using namespace std;
int main()
{
long int a, b, c, d = 0, f;
int w = 0;
f = 13195;
for(a = 3; a < 100; a++)
{
w = f % a;
if(w == 0)
{
for(b = 2; b < a; b++)
{
d = 0;
c = a % b;
if(c == 0)
{
d++;
break;
}
}
if(d == 0)
cout << a << " is a prime\n";
}
}
system("pause");
return 0;
}
f is the number to be checked. I have to check a 12 digit number, but I cannot use double and long int as % cannot act on both together. What can I do instead?
A
long longis a larger data type that can handle 64-bit (>12 digit) numbers. Using that should work.