Skip to content

Instantly share code, notes, and snippets.

@alexg228
Created August 21, 2010 23:00
Show Gist options
  • Save alexg228/542988 to your computer and use it in GitHub Desktop.
Save alexg228/542988 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;
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