Advertisement
Qellex

2 - 10 в

Mar 4th, 2022
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <stdio.h>
  4. #include <locale.h>
  5. #include <windows.h>
  6. using namespace std;
  7.  
  8. struct KVY {
  9.     double a;
  10.     double b;
  11.     double c;
  12.  
  13. };
  14. KVY* Create(double a, double b, double c) {
  15.     KVY* yr = new KVY();
  16.     if (aaa == 0) {
  17.         cout << "Введите значение не равное нулю: ";
  18.         cin >> aaa;
  19.     }
  20.     yr->a = a;
  21.     yr->b = b;
  22.     yr->c = c;
  23.     return yr;
  24. };
  25.  
  26. void ref(KVY* f, double* x3, double* x4, int *g) {
  27.     double D = f->b * f->b*1. - 4. * f->a * f->c;
  28.     if (D > 0) {
  29.         *x3 = ((-1 * f->b + sqrt(D)) / (2 * f->a));
  30.         *x4 = ((-1 * f->b - sqrt(D)) / (2 * f->a));
  31.         *g = 2;
  32.     }
  33.     if (D == 0) {
  34.         *x3 = -f->b / (2 * f->a);
  35.         *g = 1;
  36.     }
  37.     if (D < 0) {
  38.         *g = 0;
  39.     }
  40. }
  41. void print(KVY* f) {
  42.     double x1, x2;
  43.     int i;
  44.     ref(f, &x1, &x2, &i);
  45.     cout << "Ответ: ";
  46.     if (i == 0) cout << "Решения нет!\n";
  47.     if (i == 1) {
  48.         cout << "x = "<< x1 << "\n";
  49.     }
  50.     if (i == 2) {
  51.         cout << "x1 = " << x1 << " x2 = " << x2 << "\n";
  52.     }
  53. }
  54. void printyr(KVY* f) {
  55.     cout << "Введенное уравниение: " << f->a << " * x^2 + " << f->b << " * x + " << f->c << "\n";
  56. }
  57.  
  58. int main()
  59. {
  60.     SetConsoleCP(1251);
  61.     SetConsoleOutputCP(1251);
  62.     double a = 0, b = 0, c = 0;
  63.     cout << "Введите числовые коэффициенты A, B, C для A*x^2+B*x+C\n";
  64.     cout << "Введите A не равное нулю: ";
  65.     cin >> a;
  66.     cout << "Введите B: ";
  67.     cin >> b;
  68.     cout << "Введите C: ";
  69.     cin >> c;
  70.     KVY* yrav = Create(a,b,c);
  71.     printyr(yrav);
  72.     print(yrav);
  73.     system("pause");
  74.     return 0;
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement