Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <QCoreApplication>
  2. #include <iostream>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int a, b, c;
  8. float x, x1, x2, D;
  9.  
  10. int main()
  11.  
  12. {
  13. cout << "Имеем уравнение вида: ax^2+bx+c=0" << endl;
  14. cout << "Введите значение а:" << endl;
  15. cin >> a;
  16. cout << "Введите значение b:" << endl;
  17. cin >> b;
  18. cout << "Введите значение c:" << endl;
  19. cin >>c;
  20.  
  21. cout << "Решение уравнения:" << endl;
  22.  
  23. if (a == 0) {
  24. x=(-c)/b;
  25. cout << "x = " << x << endl;
  26. }
  27. if (a != 0) {
  28. D = pow(b,2)-4*a*c;
  29. cout << "D =" << D << endl;
  30.  
  31. if (D>0) {
  32. x1 = (-b-sqrt(D))/(2*a);
  33. x2 = (-b+sqrt(D))/(2*a);
  34.  
  35. cout << "x1 =" << x1 << endl;
  36. cout << "x2 =" << x2 << endl;
  37. }
  38.  
  39.  
  40. if (D<0) {
  41. cout << "Уравнение не имеет решений" << endl;
  42. }
  43. if (D == 0) {
  44.  
  45. x = (-b)/2*a;
  46.  
  47. cout << "Уравнение имеет единственный корень: " << x << endl;
  48.  
  49. }
  50. }
  51. return 0;
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement