Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include<math.h>
  3. using namespace std;
  4. // ax2 + bx + c
  5. float a, b, c, x, d, x1, x2, r1, r2;
  6. double rad;
  7.  
  8.  
  9. main()
  10. {
  11. cout << "Ecuatia are forma ax*2 + bx + c, introdu valoarea lui a: "; cin >> a;
  12. cout << "Intordu valoarea lui b: "; cin >> b;
  13. cout << "Intordu valoarea lui c: "; cin >> c;
  14. d = b*b - 4*a*c;
  15. if(b == 0 && c != 0 && a != 0){return 0;}
  16. else if (a == 0)
  17. {
  18. cout << "Ecuatia devine una de gradul intai" << endl;
  19. if(b == 0 && c == 0)
  20. {
  21. cout << "Ecuatia are o infinitate de solutii \n";
  22. }
  23. else
  24. {
  25. x = c/b;
  26. cout << "Necunoscuta este egala cu: " << x << endl;
  27. }
  28. if (b == 0)
  29. {
  30. cout << "Ecuatia nu are solutii \n";
  31. }
  32. }
  33. else if (b != 0 && c != 0 && a != 0)
  34. {
  35. cout << "Delta egal cu: " << d << endl;
  36. if (d < 0){
  37. cout << "Ecuatia nu are valori reale";
  38. return 0;}
  39. if (d == 0)
  40. {
  41. cout << "X1 = " << b / 2*a << endl;
  42. }
  43. else
  44. {
  45. rad=sqrt(d);
  46. r1 = -b - rad;
  47. r2 = -b + rad;
  48. cout << "X1 = " << r1 / 2*a << endl;
  49. cout << "X2 = " << r2 / 2*a << endl;
  50. }
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement