Source.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include<math.h>
  4. #include<malloc.h>
  5. void output(char str[50])
  6. {
  7. printf(str);
  8. }
  9. double quadratic_equation(int a, int b, int c)
  10. {
  11. char result[50];
  12. double D = pow(b, 2) - 4 * a * c;
  13. if (a == 0)
  14. {
  15. double x1 = -c / b;
  16. sprintf(result, "%f\n", x1);
  17. output(result);
  18. }
  19. else if(D > 0)
  20. {
  21. if (D > 0)
  22. {
  23. double x1 = (-b + sqrt(D)) / (2 * a);
  24. double x2 = (-b - sqrt(D)) / (2 * a);
  25. sprintf(result, "%f,%f\n", x1, x2);
  26. output(result);
  27. }
  28. else if (D == 0)
  29. {
  30. double x1 = (-b) / (2 * a);
  31. sprintf(result, "%f\n", x1);
  32. output(result);
  33. }
  34. else
  35. {
  36. strcpy(result, "Êîðíåé íåò\n");
  37. output(result);
  38. }
  39. }
  40. else
  41. {
  42. strcpy(result, "Ëîæíûå äàííûå\n");
  43. output(result);
  44. }
  45. }
  46. double system_equations(int a1, int b1, int c1, int a2, int b2, int c2)
  47. {
  48. char result[50];
  49. double D = a1 * b2 - a2 * b1;
  50. if (D == 0)
  51. {
  52. strcpy(result, "Ëîæíûå äàííûå\n");
  53. output(result);
  54. }
  55. else
  56. {
  57. double x1 = (c1 * b2 - c2 * b1) / D;
  58. double x2 = (a1 * c2 - a2 * c1) / D;
  59. printf("%f, %f\n", x1, x2);
  60. output(result);
  61. }
  62. }
  63. double factorial(int a)
  64. {
  65. char result[50];
  66. if (a < 0 || (a*10)%10 != 0)
  67. {
  68. strcpy(result, "Ëîæíûå äàííûå\n");
  69. output(result);
  70. }
  71. else if (a == 0)
  72. {
  73. int F = 1;
  74. sprintf(result, "%d\n", F);
  75. output(result);
  76. }
  77. else
  78. {
  79. int F = 1;
  80. for (size_t i = 1; i <= a; i++)
  81. {
  82. F = F * i;
  83. }
  84. sprintf(result, "%d\n", F);
  85. output(result);
  86. }
  87. }
  88. void input(int n)
  89. {
  90. int result;
  91. if (n == 1)
  92. {
  93. int a, b, c;
  94. printf("Ââåäèòå a, b, c\n");
  95. scanf("%d%d%d", &a, &b, &c);
  96. quadratic_equation(a, b, c);
  97. }
  98. if (n == 2)
  99. {
  100. int a1, b1, c1, a2, b2, c2;
  101. printf("Ââåäèòå a1, b1, c1, a2, b2, c2\n");
  102. scanf("%d%d%d%d%d%d", &a1, &b1, &c1, &a2, &b2, &c2);
  103. system_equations(a1, b1, c1, a2, b2, c2);
  104. }
  105. if (n == 3)
  106. {
  107. int a;
  108. printf("Ââåäèòå a\n");
  109. scanf("%d", &a);
  110. factorial(a);
  111. }
  112. else
  113. {
  114. printf("Òàêîãî çàäàíèÿ íåò/íåâåðíî\n");
  115. }
  116. }
  117. int main()
  118. {
  119. system("chcp 1251>nul");
  120. while (1)
  121. {
  122. int n;
  123. printf("Âûáåðèòå çàäà÷êó äëÿ ðåøåíèÿ:\n1. Êâàäðàòíîå óðàâíåíèå\n2. Ñèñòåìà óðàâíåíèé\n3. Ôàêòîðèàë\n0. Âûõîä\n");
  124. scanf("%d", &n);
  125. input(n);
  126. }
  127. }