Created
August 21, 2010 22:54
-
-
Save alexg228/542979 to your computer and use it in GitHub Desktop.
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> | |
#include <math.h> | |
using namespace std; | |
// declare functions | |
int prime(int n); | |
int main() { | |
int n1; | |
int i; | |
cout << "enter a number to test for first prime above "; | |
cin >> n1; | |
for (i=n1; ?; i++) { | |
if (prime(i)){ | |
cout << i << " is prime" << endl; | |
break; | |
} | |
} | |
return 0; | |
} | |
int prime(int n) { | |
int i; | |
int sn; | |
sn = sqrt((double)n); | |
for(i=2; i<=sn; i++) { | |
if(n%i==0) | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment