diff options
| author | Kamen Mladenov <kamen.d.mladenov@protonmail.com> | 2021-02-24 12:53:10 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-24 12:53:10 +0200 |
| commit | c97bf5c6e573b7b987a34ae4b41440dd849010b4 (patch) | |
| tree | 146101618fed7dc63909ed4f34929c1a43caf034 | |
| parent | d4b5cde4dad18d61979fcff886b2caf23d3ff9af (diff) | |
| download | Self-learning-c97bf5c6e573b7b987a34ae4b41440dd849010b4.tar Self-learning-c97bf5c6e573b7b987a34ae4b41440dd849010b4.tar.gz Self-learning-c97bf5c6e573b7b987a34ae4b41440dd849010b4.zip | |
Added a small C++ project
| -rw-r--r-- | C++/trig-functions.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/C++/trig-functions.cpp b/C++/trig-functions.cpp new file mode 100644 index 0000000..ccc4ad5 --- /dev/null +++ b/C++/trig-functions.cpp @@ -0,0 +1,37 @@ +#include <iostream> +#include <cmath> + +using namespace std; + +int main() +{ + const double degr = 360; + const int func = 4; + + double rad = degr * M_PI / 180.0; + + switch(func) { + case 1: // sin + printf("sin%.f = %.4f\n", degr, sin(rad)); + break; + case 2: // cos + printf("cos%.f = %.4f\n", degr, cos(rad)); + break; + case 3: // tan + if (rad == M_PI_2 || rad == 3 * M_PI_2) + cout << "Division by 0!" << endl; + else + printf("tg%.f = %.4f\n", degr, tan(rad)); + break; + case 4: // cotan + if (fmod(rad, M_PI) == 0) + cout << "Division by 0!" << endl; + else + printf("cotg%.f = %.4f\n", degr, 1 / tan(rad)); + break; + default: + cout << "Wrong function number!" << endl; + break; + } + return 0; +} |
