C++ Program to Illustrate Trigonometric Functions

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.

  1. /*
  2.  * C++ Program to Illustrate Trigonometric functions
  3.  */
  4. #include <iostream>
  5. #include <iomanip>
  6. #include <cmath>
  7. const double PI = 3.14159265;
  8.  
  9. int main()
  10. {
  11.     double degrees, radians;
  12.  
  13.     std::cout << "Enter angle in degrees ";
  14.     std::cin >> degrees;
  15.     // Trigonometric functions accept angles in radians
  16.     radians = degrees * PI / 180.0;
  17.     std::cout << "Value of trigonometric ratios " << std::endl;
  18.     std::cout << "cos(radians) = " << std::setprecision(3)
  19.               << cos(radians) << std::endl;
  20.     std::cout << "sin(radians) = " << std::setprecision(3)
  21.               << sin(radians) << std::endl;
  22.     std::cout << "tan(radians) = " << std::setprecision(3)
  23.               << tan(radians) << std::endl;
  24.     return 0;
  25. }

$ 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]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.