PTA -----近似求Π

PTA -----近似求Π

#include <stdio.h>
int main()
{
    double eps, sum=1, i, temp=1;
    scanf("%le", &eps);
    for(i=1; temp>eps; i++)
    {
        temp = temp*i/(2*i+1);
        sum += temp;
    }
    printf("PI = %.5f\n", 2*sum);
    return 0;
}

猜你喜欢

转载自blog.51cto.com/14737345/2486691
PTA