X-Git-Url: http://svarog.pmf.uns.ac.rs/gitweb/?p=mjc2wsl.git;a=blobdiff_plain;f=samples%2Feratos.mj;fp=samples%2Feratos.mj;h=620bd2daa1af7fe783cd2fd6adbd5a075b94239d;hp=0000000000000000000000000000000000000000;hb=6b96ddc43ce994ef402a19b106c283e571d45219;hpb=e3140851cb2899b2a352ef2825317bc939f5bf50 diff --git a/samples/eratos.mj b/samples/eratos.mj new file mode 100644 index 0000000..620bd2d --- /dev/null +++ b/samples/eratos.mj @@ -0,0 +1,38 @@ +program Eratos + + char[] sieve; + int max; // maximum prime to be found + int npp; // numbers per page + +{ + void put(int x) + { + if (npp == 10) {print(chr(13)); print(chr(10)); npp = 0;} + print(x, 5); + npp++; + } + + void found(int x) + int i; + { + put(x); + i = x; + while (i <= max) {sieve[i] = 'o'; i = i + x;} + } + + void main() + int i; + { + read(max); + npp = 0; + sieve = new char[max+1]; + i = 0; + while (i <= max) {sieve[i] = 'x'; i++;} + i = 2; + while (i <= max) { + found(i); + while(i <= max && sieve[i] == 'o') i++; + } + } + +}//test \ No newline at end of file