Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<math.h>
- using namespace std;
- // ax2 + bx + c
- float a, b, c, x, d, x1, x2, r1, r2;
- double rad;
- main()
- {
- cout << "Ecuatia are forma ax*2 + bx + c, introdu valoarea lui a: "; cin >> a;
- cout << "Intordu valoarea lui b: "; cin >> b;
- cout << "Intordu valoarea lui c: "; cin >> c;
- d = b*b - 4*a*c;
- if(b == 0 && c != 0 && a != 0){return 0;}
- else if (a == 0)
- {
- cout << "Ecuatia devine una de gradul intai" << endl;
- if(b == 0 && c == 0)
- {
- cout << "Ecuatia are o infinitate de solutii \n";
- }
- else
- {
- x = c/b;
- cout << "Necunoscuta este egala cu: " << x << endl;
- }
- if (b == 0)
- {
- cout << "Ecuatia nu are solutii \n";
- }
- }
- else if (b != 0 && c != 0 && a != 0)
- {
- cout << "Delta egal cu: " << d << endl;
- if (d < 0){
- cout << "Ecuatia nu are valori reale";
- return 0;}
- if (d == 0)
- {
- cout << "X1 = " << b / 2*a << endl;
- }
- else
- {
- rad=sqrt(d);
- r1 = -b - rad;
- r2 = -b + rad;
- cout << "X1 = " << r1 / 2*a << endl;
- cout << "X2 = " << r2 / 2*a << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement