Skip to content

Instantly share code, notes, and snippets.

@cruxrebels
Created April 26, 2016 15:51
Show Gist options
  • Save cruxrebels/f6db157b331f0f237cc5270fc53a13f5 to your computer and use it in GitHub Desktop.
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/
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