Advertisement
Guest User

Untitled

a guest
Oct 12th, 2016
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <iostream>
  5. int main()
  6. {
  7. setlocale(LC_ALL, "Russian");
  8. double x1;
  9. double x2;
  10. double dx;
  11. double a;
  12. double b;
  13. double c;
  14. printf("Enter a: ");
  15. scanf("%lf", &a);
  16. printf("Enter b: ");
  17. scanf("%lf", &b);
  18. printf("Enter c: ");
  19. scanf("%lf", &c);
  20. do
  21. {
  22. printf("Enter x1: ");
  23. scanf("%lf", &x1);
  24. printf("Enter x2: ");
  25. scanf("%lf", &x2);
  26. printf("Enter dx: ");
  27. scanf("%lf", &dx);
  28. } while ((x2 <= x1) && (dx >= fabs(x2 - x1)));
  29.  
  30. int const lines = 3;
  31. int l;
  32. double x = x1, f;
  33.  
  34. while (x <= x2)
  35. {
  36.  
  37. printf("-----------------------------\n");
  38. printf("| x | f |\n");
  39. printf("-----------------------------\n");
  40.  
  41. for (l = 1; ((x <= x2) && (l <= lines)); l++, x += dx)
  42. {
  43.  
  44.  
  45. if ((x > 0) && (b == 0))
  46. {
  47. if (((x - a) != 0) || ((x - c) != 0))
  48. {
  49. f = ((x - a) / (x - c));
  50. printf("| %11.3lf | %11.3lf |\n", x, f);
  51.  
  52. }
  53. else
  54. {
  55. printf("| %11.3lf | error |\n", x);
  56. }
  57.  
  58. }
  59. else
  60. if ((x < 0) && (b != 0))
  61. {
  62. f = (x * x + b);
  63. printf("| %11.3lf | %11.3lf |\n", x, f);
  64.  
  65. }
  66. else
  67.  
  68. if (c != 0)
  69. {
  70. f = (x / c);
  71. printf("| %11.3lf | %11.3lf |\n", x, f);
  72. }
  73. else
  74. {
  75. printf("| %11.3lf | error |\n", x);
  76. }
  77.  
  78.  
  79.  
  80. }
  81.  
  82. printf("-----------------------------\n");
  83. if (x <= x2)
  84. {
  85. printf("Press ENTER for continue: ");
  86. if (getchar() != '\n')
  87. break;
  88. }
  89. }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement