-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqrt.cpp
More file actions
28 lines (26 loc) · 702 Bytes
/
Copy pathsqrt.cpp
File metadata and controls
28 lines (26 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <tuple>
#include <iostream>
#include <string>
#include <stdexcept>
#include <math.h>
std::pair<double, double> findRoots(double a, double b, double c)
{
std::pair<double, double> result;
try
{
result.first = (-b + sqrt(b*b-4*a*c))/(2*a);
result.second = (-b - sqrt(b*b-4*a*c))/(2*a);
}
catch(std::out_of_range ex)
{
std::cout<< "this function does not work with complex numbers!\n"<<ex.what();
}
return result;
}
#ifndef RunTests
int main()
{
std::pair<double,double> roots = findRoots(2, 10, 8);
std::cout << "Roots: " + std::to_string(roots.first) + ", " + std::to_string(roots.second);
}
#endif