Created
September 22, 2013 13:30
-
-
Save Zulqurnain/34336cea81b012ce3668 to your computer and use it in GitHub Desktop.
Program To Check Entered Number is prime or not !
This file contains 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
#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