Skip to content

Instantly share code, notes, and snippets.

@bemasher
Forked from alexg228/findthenextprime.cpp
Created August 21, 2010 23:02
Show Gist options
  • Save bemasher/542990 to your computer and use it in GitHub Desktop.
Save bemasher/542990 to your computer and use it in GitHub Desktop.
#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