圆周率的问题
圆周率应该怎么定义?#include <stdio.h>
#include <math.h>
#include <stdlib.h>
// declare function
double f(double x);
// defind function
double f(double x)
{
return (3.1415926(x*x*x-30*x*x+1000))/3;
}
int main()
{
double mid;
double e=0.000001
double a=0;
double b=30;
double y;
while (abs(b-a)>e)
{
mid=(a+b)/2;
y=f(a)*f(mid);
if (y<0)
b=mid;
else
a=mid;
}
printf("%lf \n",mid);
return 0;
}
[此贴子已经被作者于2017-3-7 14:50编辑过]