- #1
Whovian
- 652
- 3
Alright. I know how incredibly inefficient this algorithm is, but I felt like giving this a whirl.
#include <iostream>
#include <cmath>
using namespace std;
bool prime(int x)
{
bool j = true;
for (double i = 2;i == x;i++)
{
if (x/i == floor(x/i))
{
j = false;
}
}
return j;
}
int main()
{
cout << prime(4) << endl;
return 0;
}
It returns "1" (true.) Why is this? Obviously, an error on my part.
#include <iostream>
#include <cmath>
using namespace std;
bool prime(int x)
{
bool j = true;
for (double i = 2;i == x;i++)
{
if (x/i == floor(x/i))
{
j = false;
}
}
return j;
}
int main()
{
cout << prime(4) << endl;
return 0;
}
It returns "1" (true.) Why is this? Obviously, an error on my part.
Last edited: