#include <stdlib.h>
#include <stdio.h>

float kahan_sum(int N) {
    float sum = 0.0, c = 0.0, t, y;

    for( int i = 1; i <= N; i++ ) {
        y = 1.0/i - c;
        t = sum + y;
        c = (t - sum) - y;
        sum = t;
    }

    return sum;
}

int main(void) {
    printf("N = 1e8: %f\n", kahan_sum(1e8));
    printf("N = 2e8: %f\n", kahan_sum(2e8));

    return 0;
}
