Advertisement
Guest User

ur

a guest
Feb 28th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1.  
  2. #include <iostream>
  3.  
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8.  
  9.  
  10. bool checkA(float num)
  11.  
  12. {
  13.  
  14. if (num != 0)
  15.  
  16. {
  17.  
  18. return true;
  19.  
  20. }
  21.  
  22. else
  23.  
  24. return false;
  25.  
  26. }
  27.  
  28. float findDisc(float a, float b, float c)
  29.  
  30. {
  31.  
  32. float D;
  33.  
  34. D = (pow(b, 2) - (4 * a * c));
  35.  
  36. return D;
  37.  
  38. }
  39.  
  40. void roots(float a, float b, float c)
  41.  
  42. {
  43.  
  44. float Disc = findDisc(a, b, c);
  45.  
  46. if (Disc>0)
  47.  
  48. {
  49.  
  50. cout << "x1= " << (-b + sqrt(Disc)) / 2 * a << endl;
  51.  
  52. cout << "x2= " << (-b - sqrt(Disc)) / 2 * a << endl;
  53.  
  54. }
  55.  
  56. else if (Disc==0)
  57.  
  58. {
  59.  
  60. cout << "x1 = x2 = " << (-b) / 2 * a << endl;
  61.  
  62. }
  63.  
  64. else if (Disc < 0)
  65.  
  66. {
  67.  
  68. cout << "No Roots" << endl;
  69.  
  70. }
  71.  
  72.  
  73.  
  74. }
  75.  
  76.  
  77.  
  78. int main()
  79.  
  80. {
  81.  
  82. float a, b, c;
  83.  
  84. cout << "Enter a: "; cin >> a;
  85.  
  86. cout << "Enter b: "; cin >> b;
  87.  
  88. cout << "Enter c: "; cin >> c;
  89.  
  90. if (checkA(a) == true)
  91.  
  92. {
  93.  
  94. cout << "Discriminant: " << findDisc(a, b, c) << endl;
  95.  
  96. roots(a, b, c);
  97.  
  98. }
  99.  
  100. else
  101.  
  102. {
  103.  
  104. cout << "When a = 0, there is one root" << endl;
  105.  
  106. cout << "x = c/b = " << c/b << endl;
  107.  
  108. }
  109.  
  110. return 0;
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement