Write a program to find prime number in minimum time complexity
Here is an example how to find prime number in optimized way. This approach is also very useful when you go for an interview.
In this approach input number from user take the square root of a number and then run loop from upto square root of the number.
cout<<"Enter the number to check";
double value = sqrt(num);
cout<<"number is not prime";
cout<<"number is prime";
Post a Comment