This C++ program illustrates the use of trigonometric functions. The trigonometric functions are declared in ‘math.h’ or ‘cmath’ header which is included in this program. The angles in radians are passed as parameters to these functions.
Here is the source code of the C++ program illustrates the use of trigonometric functions. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to Illustrate Trigonometric functions
*/
#include <iostream>
#include <iomanip>
#include <cmath>
const double PI = 3.14159265;
int main()
{
double degrees, radians;
std::cout << "Enter angle in degrees ";
std::cin >> degrees;
// Trigonometric functions accept angles in radians
radians = degrees * PI / 180.0;
std::cout << "Value of trigonometric ratios " << std::endl;
std::cout << "cos(radians) = " << std::setprecision(3)
<< cos(radians) << std::endl;
std::cout << "sin(radians) = " << std::setprecision(3)
<< sin(radians) << std::endl;
std::cout << "tan(radians) = " << std::setprecision(3)
<< tan(radians) << std::endl;
return 0;
}
$ a.out Enter angle in degrees 30 Value of trigonometric ratios cos(radians) = 0.866 sin(radians) = 0.5 tan(radians) = 0.577
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Next Steps:
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Buy C++ Books
- Apply for C++ Internship
- Buy Programming Books
- Practice Computer Science MCQs
- Apply for Information Technology Internship