Skip to content

Instantly share code, notes, and snippets.

@milon
Created January 19, 2018 01:50
Show Gist options
  • Select an option

  • Save milon/d1fa137915c89966e5a1f5ffa9bbda5c to your computer and use it in GitHub Desktop.

Select an option

Save milon/d1fa137915c89966e5a1f5ffa9bbda5c to your computer and use it in GitHub Desktop.
Prime Number
//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