Skip to content

Instantly share code, notes, and snippets.

@kennethzfeng
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save kennethzfeng/db250ff555d445fea6eb to your computer and use it in GitHub Desktop.

Select an option

Save kennethzfeng/db250ff555d445fea6eb to your computer and use it in GitHub Desktop.
C++ Exercise
#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;
}
}
all:
clang++ main.cpp -o main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment