fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. double f(double x, double a, double k) {
  4. double result;
  5. if (a == 0 || x == 0 || x == a) {
  6. printf("Cannot compute a function for x = %.2lf\n", x);
  7. return 0;
  8. }
  9. result = pow(cos(a * x), 1. / 3) + (k * log(a - x)) / log(a * x);
  10. return result;
  11. }
  12. int main() {
  13. double xmin, xmax, dx;
  14. double a, k;
  15. double x, y;
  16.  
  17. printf("Enter the value xmin: ");
  18. scanf("%lf", &xmin);
  19. printf("Enter the value xmax: ");
  20. scanf("%lf", &xmax);
  21. printf("Enter the value step dx: ");
  22. scanf("%lf", &dx);
  23. printf("Enter the value a: ");
  24. scanf("%lf", &a);
  25. printf("Enter the value k: ");
  26. scanf("%lf", &k);
  27.  
  28. printf("Tabulation function f(x):\n");
  29. printf("-----------------------\n");
  30. printf(" x | f(x) \n");
  31. printf("-----------------------\n");
  32.  
  33. for (x = xmin; x <= xmax; x += dx) {
  34. y = f(x, a, k);
  35. printf("%8.2lf | %10.4lf\n", x, y);
  36. }
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5468KB
stdin
0
0.1
0.01
0.3
3
stdout
Enter the value xmin: Enter the value xmax: Enter the value step dx: Enter the value a: Enter the value k: Tabulation function f(x):
-----------------------
   x      |      f(x)   
-----------------------
Cannot compute a function for x = 0.00
    0.00 |     0.0000
    0.01 |     1.6393
    0.02 |     1.7465
    0.03 |     1.8339
    0.04 |     1.9137
    0.05 |     1.9902
    0.06 |     2.0657
    0.07 |     2.1412
    0.08 |     2.2178
    0.09 |     2.2961
    0.10 |     2.3768