Created
January 19, 2018 01:50
-
-
Save milon/d1fa137915c89966e5a1f5ffa9bbda5c to your computer and use it in GitHub Desktop.
Prime Number
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
| //Prime number check | |
| //Author: Milon | |
| #include<iostream> | |
| using namespace std; | |
| bool isPrime(int num){ | |
| if(num<2) | |
| return false; | |
| for(int i=2;i<num;i++) | |
| if(num%i==0) | |
| return false; | |
| return tru e; | |
| } | |
| int main(){ | |
| int n; | |
| while(cin>>n && n){ | |
| if(isPrime(n)) | |
| cout<<n<<" is a prime number."<<endl; | |
| else | |
| cout<<n<<" is not a prime number."<<endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment