Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main() {
- int a, b, c, delta, x1, x2;
- cout << endl;
- cout << " Calculul ecuatiei de gradul II" << endl << endl << endl;
- cout << " Introduceti coeficientii ecuatiei" << endl << endl;
- cout << " ax^2 + bx + c = 0" << endl << endl;
- cout << " a = "; cin >> a;
- cout << " b = "; cin >> b;
- cout << " c = "; cin >> c;
- delta = b*b - 4 * a * c;
- cout << endl;
- if (delta < 0)
- cout << "Ecuatia nu are solutii reale";
- else {
- cout << " Solutiile ecuatiei sunt:" << endl << endl;
- if (delta == 0) {
- cout << " x1 = x2 = ";
- if (-b / 2 * a == (int)(-b / 2 * a))
- cout << -b / 2 * a;
- else
- cout << -b << "/" << 2 * a;
- }
- else
- if (sqrt(delta) == (int)(sqrt(delta)))
- if ((-b + sqrt(delta)) / 2 * a == (int)((-b + sqrt(delta)) / 2 * a)) {
- cout << " x1 = " << (-b + sqrt(delta)) / 2 * a << endl;
- cout << " x2 = " << (-b - sqrt(delta)) / 2 * a;
- }
- else {
- cout << " x1 = " << -b + sqrt(delta) << "/" << 2 * a << endl;;
- cout << " x2 = " << -b - sqrt(delta) << "/" << 2 * a;
- }
- else
- if (-b / 2 * a == (int)(-b / 2 * a)) {
- cout << " x1 = " << -b / 2 * a << " + rad(" << delta << ") / " << 2 * a << endl;
- cout << " x2 = " << -b / 2 * a << " - rad(" << delta << ") / " << 2 * a;
- }
- else {
- cout << " x1 = " << b << " + rad(" << delta << ") / " << 2 * a << endl;
- cout << " x2 = " << b << " - rad(" << delta << ") / " << 2 * a;
- }
- }
- cout << endl << endl;
- cout << ' ';
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement