Advertisement
Underhing

Untitled

Dec 29th, 2021
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. #include <stdio.h>
  2. // #include <complex.h>
  3. #include <math.h>
  4.  
  5. /*
  6. double logbase(double a, double base)
  7. {
  8. return log(a) / log(base);
  9. }
  10. */
  11.  
  12.  
  13. int main()
  14. {
  15. /*
  16. x, s = 0;
  17. ap = x;
  18.  
  19. s += ap;
  20. y = ;
  21. an = ap*y;
  22. ap = an;
  23. an > e;
  24.  
  25. */
  26. printf("\nВведите x:\n");
  27. double x;
  28. scanf("%lf", &x);
  29.  
  30. // double target = x;
  31. double sum = 0;
  32. double n = 1;
  33. // double a = 1;
  34.  
  35. printf("\nВведите E (точность числа, ex:0.001):\n");
  36. double e;
  37. scanf("%lf", &e);
  38.  
  39. double an;//, ap;
  40. //ap = x;
  41. an = x;
  42. do
  43. {
  44. sum += an;
  45. //ap = an;
  46.  
  47. an = an * (-(x*x)/(2*n*(2*n+1)));
  48. //ap = an;
  49. n += 1;
  50. printf("элемент(%d): %lf\t| сумма: %lf\n", (int)n, an, sum);
  51. } while (fabs(an) > e);
  52.  
  53. printf("\nОтвет: %lf. От библиотеки math.h: %lf\n\n", sum, sin(x));
  54. /*
  55. printf("\nВведите дробное число:\n\n");
  56. double num;
  57. scanf("%lf", &num);
  58. printf("\nВведите степень:\n\n");
  59. double degree;
  60. scanf("%lf", &degree);
  61. printf("\nОтвет:%lf\n", exp(degree * log(num)));
  62. */
  63.  
  64. /*
  65. // лаба 5
  66.  
  67. printf("\nВведите дробное число:\n\n");
  68. double target;
  69. scanf("%lf", &target);
  70.  
  71. double i = 0.5; // 1/(2^n)
  72. int r = 0;
  73. printf("0.");
  74. while (target - i != 0 && limit != 0){
  75. if (i <= target){
  76. printf("1");
  77. limit -= 1;
  78. target -= i;
  79. } else printf("0");
  80. i /= 2;
  81. }
  82.  
  83. printf("1\nГотово.\n\n\n");
  84. */
  85. /*
  86. // лаба 5
  87. printf("Введите коэффициенты при X квадратного уравнения, вида AX^2 + BX + C = 0.\n\n");
  88. double a, b, c;
  89. double complex d, x1, x2;
  90. printf("\nВведите A: ");
  91. scanf("%lf", &a);
  92. printf("Введите B: ");
  93. scanf("%lf", &b);
  94. printf("Введите C: ");
  95. scanf("%lf", &c);
  96. if (a != 0){
  97. d = csqrt(b * b - (4 * a * c));
  98. x1 = (-b + d) / (2.0*a);
  99. x2 = (-b - d) / (2.0*a);
  100. printf("\nx1 = %.2f + (%.2fi);\nx2 = %.2f + (%.2fi);", creal(x1), cimag(x1), creal(x2), cimag(x2));
  101. } else {
  102. if (b == 0) printf("Перезапустите программу заново и повторите ввод коэффициентов при X, исключая, что a=0 и b=0.");
  103. else printf("x = %.2f;", -(c/b));
  104. }
  105. printf("\n");
  106. */
  107. /* // лаба 4
  108. double x,y;
  109. printf("\nВведите x: ");
  110. scanf("%lf", &x);
  111. printf("Введите y: ");
  112. scanf("%lf", &y);
  113. if (x < 0.0 && y < 0.0){
  114. x = fabs(x);
  115. y = fabs(y);
  116. } else {
  117. if ((x > 0.0 && y < 0.0) || (x < 0.0 && y > 0.0)) {
  118. x *= 0.5;
  119. y *= 0.5;
  120. } else {
  121. if ((x >= 0.5 && x <= 2.0) && (y >= 0.5 && y <= 2.0)) {
  122. x /= 10.0;
  123. y /= 10.0;
  124. }
  125. }
  126. }
  127. printf("x = %lf; y = %lf\n", x, y);
  128. */
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement