Last active
August 29, 2015 13:56
-
-
Save bitwiser/9206761 to your computer and use it in GitHub Desktop.
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
/* 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