fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5. double K = 3.0, L = 12.48;
  6. double xs[] = {2.005, -0.437, -2.47};
  7.  
  8. for (int i = 0; i < 3; i++) {
  9. double x = xs[i];
  10. printf("--- Step %d: x = %.3f ---\n", i + 1, x);
  11.  
  12. if (x == 0) {
  13. printf("Error: Division by zero (x=0)\n\n");
  14. continue;
  15. }
  16.  
  17. double a = tan(pow(sqrt(K), pow(K, 1.0/3.0))) - 1.0/(2.0*x);
  18.  
  19. double denomB = pow(0.842, 4) * sqrt(8 * K) * cos(4 * x);
  20. if (fabs(denomB) < 1e-12) {
  21. printf("Error: Division by zero in b\n\n");
  22. continue;
  23. }
  24.  
  25. double b = (sin(2 * x) * L * pow(5.75, 1.0/3.0)) / denomB;
  26. double ab = a * b;
  27. double y;
  28.  
  29. if (ab < 0) {
  30. double denomY = 2 * a + 5 * b;
  31. if (fabs(denomY) < 1e-12) {
  32. printf("Error: Division by zero in y\n\n");
  33. } else {
  34. y = (a - 2 * b) / denomY;
  35. printf("a: %.4f, b: %.4f, Y: %.4f\n\n", a, b, y);
  36. }
  37. } else {
  38. y = sqrt(ab);
  39. printf("a: %.4f, b: %.4f, Y: %.4f\n\n", a, b, y);
  40. }
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
--- Step 1: x = 2.005 ---
a: -1.5994, b: 41.9392, Y: -0.4139

--- Step 2: x = -0.437 ---
a: -0.2059, b: 39.5026, Y: -0.4019

--- Step 3: x = -2.470 ---
a: -1.1476, b: -9.8487, Y: 3.3619