0
write the program that tells you whether the number you enter is a prime number.
3 odpowiedzi
+ 1
int num = 3;
if(num > 2){
for(int i=0;i < num/2;i++){
if(num%i == 0){
return true;
}
}
}
return false;
+ 1
template <typename Int>
bool prime(const Int num)
{
if (num <= 3)
return true;
for (Int i{2}; i != num / 2 + 1; ++i)
if (num % i == 0)
return false;
return true;
}
#include <iostream>
int main()
{
long long in;
std::cin >> in;
std::cout << std::boolalpha << prime(in);
}
+ 1
Ariela Your solution doesn't compile and every result is wrong.
1 -> false
2 -> false
3+ -> 0 modulus -> undefined, maybe running forever
Not meaning to blame you, I'm just honest.