a = 1.0 * k / x;
试试
#include <stdio.h> #include<math.h> int main() { double pi=4*atan(1.0);printf("%.8lf",pi); }
#include<stdio.h> #include<math.h> int main() { int sign = 1; double pi = 0.0, n = 1.0, term = 1.0;//term表示当前项 while (fabs(term) >= 1e-6) { pi += term; n += 2; sign = -sign; term = sign / n; } pi *= 4; printf("pi=%10.8f\n", pi); return 0; }