HOJ 1331 Deck

http://acm.hit.edu.cn/hoj/problem/view?id=1331

#include 
#include 

double f(int n);

int main()
{
    int n;

    printf("# Cards  Overhang\n");
    while (scanf("%d", &n) != EOF)
    {
        printf("%5d     %.3lf\n", n, f(n));
    }

    return 0;
}

double f(int n)
{
    int i;
    double s=0;
    for(i = 2; i <= 2*n; i += 2)
    {
        s += 1.0/i;
    }
    return s;
}


 

你可能感兴趣的:(HOJ)