### Blame Examples/primes.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 if (limit >= 2) print "prime 1 = 2\n" Packit 70b277 if (limit >= 3) print "prime 2 = 3\n"; 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 print "prime ", num, " = ", p, "\n" Packit 70b277 } Packit 70b277 } Packit 70b277 } Packit 70b277 Packit 70b277 Packit 70b277 print "\ntyping 'primes (10)' will print all primes less than 10.\n"