Skip to content

Instantly share code, notes, and snippets.

@kdmkdmkdm
Created May 1, 2012 18:34
Show Gist options
  • Select an option

  • Save kdmkdmkdm/2570310 to your computer and use it in GitHub Desktop.

Select an option

Save kdmkdmkdm/2570310 to your computer and use it in GitHub Desktop.
Arc Tangent 2
// giArcTangent2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;
float MyArcTangent(float y, float x);
int main()
{
cout << "MyArcTangent( 4, 2) = " << MyArcTangent( 4, 2) << endl;
cout << "MyArcTangent( 5, -1) = " << MyArcTangent( 5, -1) << endl;
cout << "MyArcTangent( -4, -6) = " << MyArcTangent( -4, -6) << endl;
cout << "MyArcTangent( -6, 4) = " << MyArcTangent( -6, 4) << endl;
}
float MyArcTangent(float y, float x)
{
if(x >= 0)
{
float PI = 3.14;
float answer = atanf(y/x);
answer = (answer * 180) / PI;
return answer;
}
else
{
float PI = 3.14;
float answer = atanf(y/x);
answer = ((answer * 180) / PI) + 180;
return answer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment