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.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Check Programming Books
- Practice Programming MCQs
- Check C++ Books
- Apply for C++ Internship
- Practice Computer Science MCQs