complex1.cminus 1.14 KB
Newer Older
lxq's avatar
lxq committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/*
     This code is adapted from Dik T. Winter at CWI
     It computes pi to 800 decimal digits
 */

int mod(int a, int b) { return a - a / b * b; }

void printfour(int input) {
    int a;
    int b;
    int c;
    int d;
    input = mod(input, 10000);
    d = mod(input, 10);
    input = input / 10;
    c = mod(input, 10);
    input = input / 10;
    b = mod(input, 10);
    input = input / 10;
    a = input;
    output(a);
    output(b);
    output(c);
    output(d);
    return;
}

void main(void) {
    int r[2801];
    int i;
    int k;
    int b;
    int d;
    int c;
    c = 0;
    d = 1234;

    {
        int mod;
        mod = 0;
        while (mod < 2800) {
            r[mod] = 2000;
            mod = mod + 1;
        }
    }

    k = 2800;
    while (k) {
        int d;
        d = 0;
        i = k;

        while (i != 0) {
            d = d + r[i] * 10000;
            b = 2 * i - 1;
            r[i] = mod(d, b);
            d = d / b;
            i = i - 1;
            if (i != 0) {
                d = d * i;
            }
        }

        printfour(c + d / 10000);
        c = mod(d, 10000);

        k = k - 14;
    }

    return;
}