-
-
Save bemasher/542990 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; | |
bool isprime; | |
cout << "enter a number to test for first prime above "; | |
cin >> n1; | |
for(i = n1; !isprime; i++) { | |
isprime = prime(i); | |
} | |
cout << i << " is the next greatest prime" << endl; | |
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