X-Git-Url: http://svarog.pmf.uns.ac.rs/gitweb/?p=mjc2wsl.git;a=blobdiff_plain;f=samples%2Falpha-mj%2Feratos.mj;fp=samples%2Falpha-mj%2Feratos.mj;h=92d28f88b65b66fbbc814aecfde16e997cf7fc1e;hp=0000000000000000000000000000000000000000;hb=77e39fac55f1a366814d35e75659cb6d88cca4e1;hpb=306587b78e421a7221952e44adde831723748e4c diff --git a/samples/alpha-mj/eratos.mj b/samples/alpha-mj/eratos.mj new file mode 100644 index 0000000..92d28f8 --- /dev/null +++ b/samples/alpha-mj/eratos.mj @@ -0,0 +1,47 @@ +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