fork download
  1. //Cameron Pham CS1A Chapter 3, P. 147, #20
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * Calculate Trigonometric Values
  6.  * _____________________________________________________________________________
  7.  *
  8.  * This program asks the user to enter an angle in radians. Then, it calculates
  9.  * and displays the sine, cosine, and tangent of the angle. The results are
  10.  * displayed using fixed-point notation and rounded to four decimal places.
  11.  * _____________________________________________________________________________
  12.  *
  13.  * INPUT
  14.  * angle: Angle entered in radians
  15.  *
  16.  * OUTPUT
  17.  * sine: The sine of the angle
  18.  * cosine: The cosine of the angle
  19.  * tangent: The tangent of the angle
  20.  *
  21.  ******************************************************************************/
  22. #include <iostream>
  23. #include <iomanip>
  24. #include <cmath>
  25. using namespace std;
  26.  
  27. int main()
  28. {
  29. // Declare the variable used to store the angle entered by the user.
  30. double angle;
  31.  
  32. // Ask the user to enter an angle in radians.
  33. cout << "Enter an angle in radians: ";
  34. cin >> angle;
  35. cout << endl;
  36.  
  37. // Display the results using fixed-point notation with four digits after the
  38. // decimal point.
  39. cout << fixed << setprecision(4);
  40.  
  41. // Calculate and display the sine, cosine, and tangent of the angle.
  42. cout << "Sine: " << sin(angle) << endl;
  43. cout << "Cosine: " << cos(angle) << endl;
  44. cout << "Tangent: " << tan(angle) << endl;
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0s 5320KB
stdin
1
stdout
Enter an angle in radians: 
Sine: 0.8415
Cosine: 0.5403
Tangent: 1.5574