Skip to content

Instantly share code, notes, and snippets.

@Zulqurnain
Created September 22, 2013 13:30
Show Gist options
  • Save Zulqurnain/34336cea81b012ce3668 to your computer and use it in GitHub Desktop.
Save Zulqurnain/34336cea81b012ce3668 to your computer and use it in GitHub Desktop.
Program To Check Entered Number is prime or not !
#include <iostream.h>
int main(){ // Simple Prime Checker
int n;
cout<<"Enter Your Number :=:"; cin>>n;
/*Logic is simple ! if a number is divisible by more than 2 times ,, when approaching it from 1 to n then
its not prime else it is prime .
*/
int t=1,i=0;
while(t<=n){
if( n % t == 0 ){
i++;
}
t++;
}
if(i > 2){
cout<<"\n :: Number Is Not A Prime :: \n";
}
else{
cout<<"\n :: Number Is Prime :: \n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment