Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- bool checkA(float num)
- {
- if (num != 0)
- {
- return true;
- }
- else
- return false;
- }
- float findDisc(float a, float b, float c)
- {
- float D;
- D = (pow(b, 2) - (4 * a * c));
- return D;
- }
- void roots(float a, float b, float c)
- {
- float Disc = findDisc(a, b, c);
- if (Disc>0)
- {
- cout << "x1= " << (-b + sqrt(Disc)) / 2 * a << endl;
- cout << "x2= " << (-b - sqrt(Disc)) / 2 * a << endl;
- }
- else if (Disc==0)
- {
- cout << "x1 = x2 = " << (-b) / 2 * a << endl;
- }
- else if (Disc < 0)
- {
- cout << "No Roots" << endl;
- }
- }
- int main()
- {
- float a, b, c;
- cout << "Enter a: "; cin >> a;
- cout << "Enter b: "; cin >> b;
- cout << "Enter c: "; cin >> c;
- if (checkA(a) == true)
- {
- cout << "Discriminant: " << findDisc(a, b, c) << endl;
- roots(a, b, c);
- }
- else
- {
- cout << "When a = 0, there is one root" << endl;
- cout << "x = c/b = " << c/b << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement