Created
March 9, 2019 13:18
-
-
Save jkotra/00cb6c1e0e620b0356372af1a29be69d to your computer and use it in GitHub Desktop.
Prime number generator.
This file contains hidden or 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> | |
using namespace std; | |
void gen_prime(int limit); | |
int main() { | |
int limit; | |
cout << "generate prime numbers upto:"; | |
cin >> limit; | |
gen_prime(limit); | |
} | |
void gen_prime(int limit) { | |
int i, j, flag; | |
for (i = 2; i < limit; i++) { | |
flag = 0; | |
for (j = 2; j < i; j++) { | |
if (i % j == 0) { | |
flag = 1; | |
break; | |
} | |
} | |
if (!flag) { | |
cout << i << endl; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment