[t][TT #1119] Convert t/op/bitwise.t to PIR
[parrot.git] / examples / benchmarks / primes.c
blob3a459a7bb445959480e9ffd81b9c9a4927db2154
1 /*
2 Copyright (C) 2001-2003, Parrot Foundation.
3 $Id$
5 =head1 NAME
7 examples/benchmarks/primes.c - Calculate prime numbers < 50000
9 =head1 SYNOPSIS
11 % make examples/benchmarks/primes
12 % time examples/benchmarks/primes
14 =head1 DESCRIPTION
16 Calculates all the prime numbers up to 50000 and prints out the number
17 of primes and the last one found.
19 =head2 Functions
21 =over 4
23 =cut
27 #include <stdio.h>
31 =item C<int main(int argc, char *argv[])>
33 Main function to run the example.
35 =cut
39 int
40 main(int argc, char *argv[])
42 int I1 = 1;
43 int I2 = 50000;
44 int I3;
45 int I4;
46 int I5;
47 int I6 = 0;
48 int I7;
49 printf("N primes up to ");
50 printf("%d", I2);
51 printf(" is: ");
53 REDO:
54 I3 = 2;
55 I4 = I1 / 2;
56 LOOP:
57 I5 = I1 % I3;
58 if (I5) {goto OK;}
59 goto NEXT;
60 OK:
61 I3++;
62 if (I3 <= I4) {goto LOOP;}
63 I6++;
64 I7 = I1;
65 NEXT:
66 I1++;
67 if (I1 <= I2) {goto REDO;}
68 printf("%d\n", I6);
69 printf("last is: %d\n", I7);
71 return 0;
76 =back
78 =head1 SEE ALSO
80 F<examples/benchmarks/primes.c>,
81 F<examples/benchmarks/primes.pasm>,
82 F<examples/benchmarks/primes.pl>,
83 F<examples/benchmarks/primes2_p.pasm>,
84 F<examples/benchmarks/primes2.c>,
85 F<examples/benchmarks/primes2.pir>,
86 F<examples/benchmarks/primes2.py>.
88 =cut
93 * Local variables:
94 * c-file-style: "parrot"
95 * End:
96 * vim: expandtab shiftwidth=4: