fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define daikei(a,b,k) (((a)+(b))*(k)*0.5);
  4. double menseki(double c,double d,double n)
  5. {
  6. double r,l,S,h1,h2,k,p,z; //c,d円の始点終点 n等分 r直径 l,x座標 S面積の合計
  7. //h1一個前の台形の高さ h2今の台形の高さ k台形の高さ
  8. r=d-c;
  9. l=c;
  10. h1=h2=0;
  11. k=r/n;
  12. S=p=0;
  13. z=0;
  14.  
  15. for (int i =1;i<=n;i++){
  16. l=l+(r/n);
  17. z=l-c;
  18. h2=sqrt(r*r*0.25-z*z);
  19. S=S+daikei(h2,h1,k);
  20. h1=h2;
  21. }
  22. p=S*2;
  23. return(p);
  24. }
  25.  
  26. int main (void){
  27.  
  28. double c,d,n;
  29.  
  30. scanf("%lf",&c);
  31. scanf("%lf",&d); //円の半径
  32. scanf("%lf",&n); //n等分
  33.  
  34.  
  35. printf("%lf",menseki(c,d,n));
  36.  
  37. return (0);
  38. }
  39.  
  40.  
  41.  
Success #stdin #stdout 0s 5316KB
stdin
1
2
1
stdout
-nan