fork download
  1. //Micah Krosby CS1A Ch. 3, P. 147, # 20
  2. /*******************************************************************************
  3.  *
  4.  * CALCULATE TRIGONOMETRIC IDENTITIES OF AN ANGLE
  5.  * _____________________________________________________________________________
  6.  *
  7.  * This program finds the sine, cosine and tangent of an angle in radians.
  8.  *
  9.  * FORMULAE-
  10.  * sine = sin(angle)
  11.  * cosine = cos(angle)
  12.  * tangent = tan(angle)
  13.  * _____________________________________________________________________________
  14.  *
  15.  * INPUT-
  16.  * radians : Angle in radians
  17.  *
  18.  * OUTPUTS-
  19.  * sine : Sine of angle
  20.  * cosine : Cosine of angle
  21.  * tangent : Tangent of angle
  22.  *
  23. *******************************************************************************/
  24.  
  25. #include <iostream>
  26. #include <iomanip>
  27. #include <cmath>
  28. using namespace std;
  29.  
  30. int main() {
  31. float radians; //INPUT- Angle in radians
  32. float sine; //OUTPUT- Sine of angle
  33. float cosine; //OUTPUT- Cosine of angle
  34. float tangent; //OUTPUT- Tangent of angle
  35.  
  36. //Initialize input variable
  37. cout << "Enter angle in radians" << endl;
  38. cin >> radians;
  39.  
  40. //Calculate output variables
  41. sine = sin(radians);
  42. cosine = cos(radians);
  43. tangent = tan(radians);
  44.  
  45. //Formatted output
  46. cout << "Sine is " << fixed << setprecision(4) << sine << endl;
  47. cout << "Cosine is " << fixed << setprecision(4) << cosine << endl;
  48. cout << "Tangent is " << fixed << setprecision(4) << tangent << endl;
  49. return 0;
  50. }
Success #stdin #stdout 0s 5284KB
stdin
1.57
stdout
Enter angle in radians
Sine is 1.0000
Cosine is 0.0008
Tangent is 1255.8483