## "Fossies" - the Fresh Open Source Software Archive ### Member "bc-1.06.95/Examples/primes.b" (7 Jul 2000, 633 Bytes) of package /linux/misc/old/bc-1.06.95.tar.gz:

As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Limbo source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

```    1
2 /* An example that finds all primes between 2 and limit. */
3
4 define primes (limit) {
5     auto num, p, root, i
6
7     prime = 2;
8     prime = 3;
9     num = 2;
10     if (limit >= 2) print "prime 1 = 2\n"
11     if (limit >= 3) print "prime 2 = 3\n";
12     scale = 0;
13
14     for ( p=5; p <= limit; p += 2)  {
15     root = sqrt(p);
16     isprime = 1;
17     for ( i = 1;  i < num && prime[i] <= root; i++ ) {
18         if ( p % prime[i] == 0 ) {
19         isprime = 0;
20         break;
21             }
22     }
23     if (isprime) {
24         num += 1;
25         prime [num] = p;
26         print "prime ", num, " = ", p, "\n"
27     }
28      }
29 }
30
31
32 print "\ntyping 'primes (10)' will print all primes less than 10.\n"
```