| 1 |
int is_factorable_by(int a, int b) { |
| 2 |
/* prime is not factorable by any number >= itself */ |
| 3 |
if b >= a then return 0; end |
| 4 |
|
| 5 |
float quo := a / b; |
| 6 |
int iquo := quo; |
| 7 |
return quo = iquo; |
| 8 |
} |
| 9 |
|
| 10 |
int is_prime(int n) { |
| 11 |
if is_factorable_by(n, 2) then return 0; end |
| 12 |
if is_factorable_by(n, 3) then return 0; end |
| 13 |
if is_factorable_by(n, 5) then return 0; end |
| 14 |
if is_factorable_by(n, 7) then return 0; end |
| 15 |
|
| 16 |
/* n is prime, assuming it is not > 120 */ |
| 17 |
return 1; |
| 18 |
} |
| 19 |
|
| 20 |
int main() { |
| 21 |
int i := 2; |
| 22 |
repeat |
| 23 |
if is_prime(i) then write i; write endl; end |
| 24 |
i := i + 1; |
| 25 |
until i > 120 |
| 26 |
} |