### Blame Examples/twins.b

 Packit 70b277 Packit 70b277 ``/* An example that finds all primes between 2 and limit. */`` Packit 70b277 Packit 70b277 ``define primes (limit) {`` Packit 70b277 `` auto num, p, root, i`` Packit 70b277 Packit 70b277 `` prime[1] = 2;`` Packit 70b277 `` prime[2] = 3;`` Packit 70b277 `` num = 2;`` Packit 70b277 `` scale = 0;`` Packit 70b277 Packit 70b277 `` for ( p=5; p <= limit; p += 2) {`` Packit 70b277 `` root = sqrt(p);`` Packit 70b277 `` isprime = 1;`` Packit 70b277 `` for ( i = 1; i < num && prime[i] <= root; i++ ) {`` Packit 70b277 `` if ( p % prime[i] == 0 ) {`` Packit 70b277 `` isprime = 0;`` Packit 70b277 `` break;`` Packit 70b277 `` }`` Packit 70b277 `` }`` Packit 70b277 `` if (isprime) {`` Packit 70b277 `` num += 1;`` Packit 70b277 `` prime [num] = p;`` Packit 70b277 `` }`` Packit 70b277 `` }`` Packit 70b277 ``}`` Packit 70b277 Packit 70b277 Packit 70b277 ``print "\ntyping 'twins (10)' will print all twin primes less than 10.\n"`` Packit 70b277 Packit 70b277 ``define twins (limit) {`` Packit 70b277 `` auto i;`` Packit 70b277 Packit 70b277 `` i = primes(limit+2);`` Packit 70b277 Packit 70b277 `` for (i=1; prime[i] > 0; i++) {`` Packit 70b277 `` if ((prime[i]+2) == prime[i+1]) \`` Packit 70b277 `` print "twins are ", prime[i], " and ", prime[i+1], "\n"`` Packit 70b277 `` }`` Packit 70b277 ``}``