Created
April 26, 2016 15:51
-
-
Save cruxrebels/f6db157b331f0f237cc5270fc53a13f5 to your computer and use it in GitHub Desktop.
Given a number N, verify if N is prime or not. Return 1 if N is prime, else return 0. Example : Input : 7 Output : True Tags: InterviewBit Math Problems https://www.interviewbit.com/problems/verify-prime/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int Solution::isPrime(int A) { | |
if (A<2) | |
return 0; | |
for(auto i=2; i<=sqrt(A); ++i) | |
{ | |
if(A%i==0) | |
return 0; | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment