Skip to content

Instantly share code, notes, and snippets.

@guyhughes
Last active June 27, 2016 15:27
Show Gist options
  • Save guyhughes/1422d256c76a544608430cbd16c6ba62 to your computer and use it in GitHub Desktop.
Save guyhughes/1422d256c76a544608430cbd16c6ba62 to your computer and use it in GitHub Desktop.
trig in cpp
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <cstdio>
using namespace std;
void trig(double angle, double *sine, double *cosine, double *tangent)
{
angle = angle * M_PI / 180;
*sine=sin(angle);
*cosine=cos(angle);
*tangent=tan(angle);
}
int main ( void )
{
double sine,cosine,tangent;
double angle = 180;
trig(angle, &sine, &cosine, &tangent);
cout << angle << endl;
cout << "sin: " << sine << endl;
cout << "cos: " << cosine << endl;
cout << "tan: " << tangent << endl;
printf("%3.1f %3.1f %3.1f\n",sine,cosine,tangent);
}
trig: trig.cc
g++ -o trig trig.cc -Wall -Wextra -pipe -lm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment