33 lines
525 B
C
33 lines
525 B
C
|
#include<stdio.h>
|
|||
|
#include<stdlib.h>
|
|||
|
#include<>
|
|||
|
int main(){
|
|||
|
double x,mid ,precision=1e-10;
|
|||
|
int i=0, count=1000;
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD>Jx<EFBFBD><EFBFBD>");
|
|||
|
scanf("%lf",&x);
|
|||
|
double upper=x,lower=0;
|
|||
|
mid=(upper+lower)/2;
|
|||
|
|
|||
|
while (fabs((mid*mid)-x)> precision && i < count){
|
|||
|
mid=(upper+lower)/2;
|
|||
|
printf("#%d\t[%f,%f]\t<EFBFBD><EFBFBD>=%f\n",i+1,lower,upper,mid);
|
|||
|
i++;
|
|||
|
if(fabs(mid-x) <precision){
|
|||
|
break;
|
|||
|
}else if(mid*mid>x){
|
|||
|
upper=mid;
|
|||
|
// lower=mid;
|
|||
|
}else{
|
|||
|
// upper=mid;
|
|||
|
lower=mid;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
printf("%f",mid);
|
|||
|
return 0;
|
|||
|
}
|