Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include<cmath>
- int main()
- {
- float a, b, c, x1, x2, D;
- std::cout << "PROGRAMA ROZVJAZKY KVADRATNUX RIVNJAN" << "\n";
- std::cout << "a*x^2 + b*x + c = 0" << "\n";
- std::cout << "Vvedit koeficientu a , b, c" << "\n";
- std::cin >> a >> b >> c;
- if (a == 0 && b == 0 && c == 0)
- {
- std::cout << "rivnanja pogano obymovlene" << "\n";
- system("pause");
- exit;
- }
- else if (a ==0 && b!=0 && c==0)
- {
- float x=0;
- std::cout << "x=" << x << "\n";
- system("pause");
- exit;
- }
- else if (a != 0 && b != 0 && c == 0)
- {
- //ax^2 + bx = 0
- //x(ax-b) = 0
- //x=0 && x=b/a;
- x1 = 0;
- x2 = b / a;
- std::cout << "x1=" << x1 << "\n";
- std::cout << "x2=" << x2 << "\n";
- system("pause");
- exit;
- }
- else if (a == 0 && b != 0 && c != 0)
- {
- float x;
- //bx+c=0
- //x=-c/b
- x = -c / b;
- std::cout << "x= " << x << "\n";
- system("pause");
- exit;
- }
- else if (a == 0 && b == 0 && c != 0)
- {
- std::cout << "Rivnanja ne mae rozvjazkiv" << "\n";
- system("pause");
- exit;
- }
- else
- {
- D = b*b - 4 * a*c;
- if (D < 0) {
- std::cout << "rivnaja ne maje rozvjazkiv" << "\n";
- std::cout << "D=" << D << "\n";
- system("pause");
- exit;
- }
- else if (D == 0)
- {
- float x;
- x = (-b / (2 * a));
- std::cout << "D=" << D << "\n";
- std::cout << "x = " << x << "\n";
- system("pause");
- }
- else
- {
- x1 = (-b + sqrt(D)) / (2 * a);
- x2 = (-b - sqrt(D)) / (2 * a);
- std::cout << "D=" << D << "\n";
- std::cout << "x1=" << x1 << "\n" << "x2=" << x2 << "\n";
- system("pause");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement