Skip to content

Instantly share code, notes, and snippets.

@bitwiser
Last active August 29, 2015 13:56
Show Gist options
  • Save bitwiser/9206761 to your computer and use it in GitHub Desktop.
Save bitwiser/9206761 to your computer and use it in GitHub Desktop.
/* Add this code in Number.h */
class Number
{
private:
int val;
public:
Number(int);
bool isPrime();
bool isDivisibleBy(int);
};
/* Add this code in Number.cpp */
#include "Number.cpp"
#include <cmath>
Number::Number(int a){
this->val = a;
}
bool Number::isPrime(){
int a = this->val;
if(a==1)
return false;
if(a==2)
return true;
int sq = sqrt(a);
for(int i=2;i<=sq;i++){
if(a%i==0)
return false;
}
return true;
}
bool Number::isDivisibleBy(int d){
if(this->val % d == 0)
return true;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment