Advertisement
wojiaocbj

N

Jun 9th, 2022
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #define PI acos(-1.)
  5. double yy;
  6. double f0(double x){
  7.     return (PI - 2 * x) / (2 * sin(x) * sin(x)) - 1 / tan(x) - yy;
  8. }
  9. double findroot(double lb,double ub,double eps2,double(*pfunc)(double)){
  10.     double mid,f = 1e3;
  11.     while(fabs(f) > eps2){
  12.         mid = (lb + ub) / 2;
  13.         f = pfunc(mid);
  14.         if(lb > ub){
  15.             break;
  16.         }
  17.         else{
  18.             if(f > 0){
  19.                 lb = mid;
  20.             }
  21.             else if(f < 0){
  22.                 ub = mid;
  23.             }
  24.         }
  25.     }
  26.     return mid;
  27. }
  28. int main(int argc,char **argv){
  29.     scanf("%lf",&yy);
  30.     printf("%.6f\n",findroot(0,5000,1e-10,f0));
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement