Advertisement
VEGASo

Lab #5 Ex. 2

Nov 10th, 2022
739
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. /////////////////////////////////////////////////////////////////////////// Lab 5 Ex.2.cpp
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. extern int D;                          // Экспортируем переменную
  8. extern int discr(int a, int b, int c); // Экспортируем функцию
  9.  
  10. int main()
  11. {
  12.     setlocale(LC_ALL, "RU");
  13.     int a, b, c;
  14.  
  15.     cout << "Введите корни. \na: ";
  16.     cin >> a;
  17.  
  18.     cout << "\nb: ";
  19.     cin >> b;
  20.  
  21.     cout << "\nc: ";
  22.     cin >> c;
  23.  
  24.     discr(a, b, c);
  25.  
  26.     if (D == 0)
  27.     {
  28.         cout << "\nДискриминант: " << D << "\nЕдинственный корень : " << (-b + sqrt(D)) / 2 * a << endl;
  29.     }
  30.     else if (D > 0)
  31.     {
  32.         cout << "\nДискриминант: " << D << "\nПервый корень : " << (-b + sqrt(D)) / 2 * a << "\nВторой корень: " << (-b - sqrt(D)) / 2 * a << endl;
  33.     }
  34.     else if (D < 0)
  35.     {
  36.         cout << "\nДискриминант: " << D << "\nКорней нет.\n";
  37.     }
  38.  
  39.  
  40.     return 0;
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47. /////////////////////////////////////////////////////////////////////////// Funcs.cpp
  48. #include <iostream>
  49.  
  50. using namespace std;
  51.  
  52. int D{ 0 };
  53.  
  54. int discr(int a, int b, int c)
  55. {
  56.     D = b * b - 4 * a * c;
  57.  
  58.     return 0;
  59. }
  60.  
Advertisement
Comments
  • jshokova
    1 year
    # text 0.16 KB | 0 0
    1. extern int discr(int a, int b, int c); // Экспортируем функцию
    2. и вот это объясните, пожалуйста. Зачем так?
Add Comment
Please, Sign In to add comment
Advertisement