Last active
August 29, 2015 14:22
-
-
Save kennethzfeng/db250ff555d445fea6eb to your computer and use it in GitHub Desktop.
C++ Exercise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <cmath> | |
| using namespace std; | |
| double dis(double a, double b, double c) | |
| { | |
| double s; | |
| s = sqrt(b*b-(4*a*c)); | |
| return s; | |
| } | |
| double quada(double a, double b, double c) | |
| { | |
| double x, disc; | |
| disc = dis(a,b,c); | |
| x = -(b) + (disc) / (2 * a); | |
| return x; | |
| } | |
| int main() | |
| { | |
| double a,b,c, disc, so1, so2 ; | |
| disc = dis(a,b,c); | |
| cin >> a >> b >> c; | |
| cout << "\n\nThe Discriminate is "<< disc; | |
| if (disc > 0) | |
| { | |
| so1 = quada(a, b, c); | |
| cout << "\n\nThe first solution is: "<< so1; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| all: | |
| clang++ main.cpp -o main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment