fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5. const double K = 3.0;
  6. const double L = 12.48;
  7. double x, a, b, y, ab, denom_b, denom_y;
  8.  
  9. for (int i = 1; i <= 3; i++) {
  10. switch (i) {
  11. case 1: x = 2.005; break;
  12. case 2: x = -0.437; break;
  13. case 3: x = -2.47; break;
  14. default: continue;
  15. }
  16.  
  17. if (x == 0) {
  18. printf("x = %.3f | Error: x is zero\n", x);
  19. continue;
  20. }
  21.  
  22. a = tan(pow(sqrt(K), pow(K, 1.0/3.0))) - 1.0/(2.0*x);
  23.  
  24. denom_b = pow(0.842, 4) * sqrt(8 * K) * cos(4 * x);
  25. if (fabs(denom_b) < 1e-12) {
  26. printf("x = %.3f | Error: denom_b is zero\n", x);
  27. continue;
  28. }
  29.  
  30. b = (sin(2 * x) * L * pow(5.75, 1.0/3.0)) / denom_b;
  31. ab = a * b;
  32.  
  33. printf("ARGUMENT x = %.3f\n", x);
  34. printf("a = %.6f\n", a);
  35. printf("b = %.6f\n", b);
  36. printf("a * b = %.6f\n", ab);
  37.  
  38. if (ab < 0) {
  39. denom_y = 2 * a + 5 * b;
  40. if (fabs(denom_y) < 1e-12) {
  41. printf("Error: denom_y is zero\n");
  42. } else {
  43. y = (a - 2 * b) / denom_y;
  44. printf("RESULT y = %.6f\n", y);
  45. }
  46. } else {
  47. y = sqrt(ab);
  48. printf("RESULT y = %.6f\n", y);
  49. }
  50. printf("---------------------------\n");
  51. }
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
ARGUMENT x = 2.005
a = -1.599419
b = 41.939162
a * b = -67.078309
RESULT y = -0.413942
---------------------------
ARGUMENT x = -0.437
a = -0.205878
b = 39.502602
a * b = -8.132720
RESULT y = -0.401880
---------------------------
ARGUMENT x = -2.470
a = -1.147614
b = -9.848717
a * b = 11.302522
RESULT y = 3.361922
---------------------------