Skip to content

Instantly share code, notes, and snippets.

@kyl191
Created October 19, 2012 16:07
Show Gist options
  • Save kyl191/3919056 to your computer and use it in GitHub Desktop.
Save kyl191/3919056 to your computer and use it in GitHub Desktop.
Triangles - finding angles between lines.
#include <stdio.h>
#include <math.h>
#include <assert.h>
//c99 removed M_PI, so check if it's defined, if not, define it
#ifndef M_PI
#define M_PI acos(-1.0)
#endif
void triangles(double a, double b, double h){
assert(a>0 && b>0 && h>0);
printf("This is wrong, but the calculated angle between side a and side b is %.2f, even though we know it should be 90.\n", atan(a/b)*180.0/M_PI);
printf("The angle between side b and side h is %.2f\n", acos(b/h)*180.0/M_PI);
printf("The angle between side a and side h is %.2f\n", acos(a/h)*180.0/M_PI);
}
int main(){
triangles(3,4,5);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment