Optimized Solution for prime numbers..
-
I have written a program in c++ to check whether a number is prime or not.... I want to know if this is optimized or not.. #include using namespace std; int main() { int num; cout<<"Enter a number:"; cin>>num; if(num%6==1 || num%6==5 || num==2 || num==3) { cout<<"\n"<
-
I have written a program in c++ to check whether a number is prime or not.... I want to know if this is optimized or not.. #include using namespace std; int main() { int num; cout<<"Enter a number:"; cin>>num; if(num%6==1 || num%6==5 || num==2 || num==3) { cout<<"\n"<
If you start programming, lesson number one : do not ask whether something is optimized or not without having performance target in mind. People that ask you to optimize your code without reason just want to waste your time on trivia. Takes 1 000 000 random numbers. Then measure how much times it takes to find out whether they are prime on your machine. Then see if you can make it better with random changes and observe.
-
If you start programming, lesson number one : do not ask whether something is optimized or not without having performance target in mind. People that ask you to optimize your code without reason just want to waste your time on trivia. Takes 1 000 000 random numbers. Then measure how much times it takes to find out whether they are prime on your machine. Then see if you can make it better with random changes and observe.
I want to know that this program is better than those which are solved using loops.....????
-
I want to know that this program is better than those which are solved using loops.....????
only way to know it is to do what I told you just above. This not only depends on the code but on the compiler. A coder can't tell you without benchamrking.
-
only way to know it is to do what I told you just above. This not only depends on the code but on the compiler. A coder can't tell you without benchamrking.
Ok.... thanks a lot..
-
I have written a program in c++ to check whether a number is prime or not.... I want to know if this is optimized or not.. #include using namespace std; int main() { int num; cout<<"Enter a number:"; cin>>num; if(num%6==1 || num%6==5 || num==2 || num==3) { cout<<"\n"<
"Optimized" is not the correct category here. It is simply wrong. 25%6=1, but 25 is not prime.