C++ Mathematic Functions Inverse Trigonometric Functions Purpose The inverse trigonometric functions calculate the arcsin, arccos, or arctan of a value, returning the angle in radians. Header File math.h (asin, acos, atan, atan2) Prototypes double asin (double Angle); double acos (double Angle); double atan (double Angle); double atan2 (double Y, double X); Arguments Value X Y Return Values asin acos atan atan2 The value of the function (sin, cos, or tan) The abcissa of the angle The ordinate of the angle The principal arc sine of the argument (-π/2.. π/2), in radians The principal arc cosine of the argument (0.. π), in radians The principal arc tangent of the argument (-π/2.. π/2), in radians
The arc tangent of Y / X, in the proper quadrant (-π.. π), in radians Example #include <stdio.h> #include <math.h> #include <stdlib.h> void Display (double Value); void Display2 (double Y, double X); double Rad2Deg (double Angle); int main () { Display (.02 * (double)(rand() % 100) - 1.0); Display (.02 * (double)(rand() % 100) - 1.0); Display (.02 * (double)(rand() % 100) - 1.0); Display2 (1.0, 2.0); Display2 (1.0, -2.0); Display2 (-1.0, 2.0); Display2 (-1.0, -2.0); return 0; double Rad2Deg (double Angle) { static double ratio = 180.0 / 3.141592653589793238; return Angle * ratio; void Display (double Value) { double Radians; double Degrees; Radians = asin (Value); printf ("The arc sine of %f is %f radians = %f degrees\n", Value, Radians, Degrees); Radians = acos (Value); printf ("The arc cosine of %f is %f radians = %f degrees\n", Value, Radians, Degrees); Radians = atan (Value); printf ("The arc tangent of %f is %f radians = %f degrees\n\n", Value, Radians, Degrees); void Display2 (double Y, double X) { double Radians; double Degrees; Radians = atan2 (Y, X); printf ("The angle having an absissa of %f\n", X); printf ("and an ordinate of %f\n", Y); printf ("is %f radians = %f degrees\n\n", Radians, Degrees);
Output The arc sine of -0.400000 is -0.411517 radians = -23.578178 degrees The arc cosine of -0.400000 is 1.982313 radians = 113.578178 degrees The arc tangent of -0.400000 is -0.380506 radians = -21.801409 degrees The arc sine of 0.640000 is 0.694498 radians = 39.791819 degrees The arc cosine of 0.640000 is 0.876298 radians = 50.208181 degrees The arc tangent of 0.640000 is 0.569313 radians = 32.619243 degrees The arc sine of 0.800000 is 0.927295 radians = 53.130102 degrees The arc cosine of 0.800000 is 0.643501 radians = 36.869898 degrees The arc tangent of 0.800000 is 0.674741 radians = 38.659808 degrees The angle having an absissa of 2.000000 and an ordinate of 1.000000 is 0.463648 radians = 26.565051 degrees The angle having an absissa of -2.000000 and an ordinate of 1.000000 is 2.677945 radians = 153.434949 degrees The angle having an absissa of 2.000000 and an ordinate of -1.000000 is -0.463648 radians = -26.565051 degrees The angle having an absissa of -2.000000 and an ordinate of -1.000000 is -2.677945 radians = -153.434949 degrees
Latihan 1 : #include <iostream.h> #include <conio.h> #include <math.h> void hitung_sinus (float a) { float sinus; sinus=sin(a); cout<<"\nsinus dari angka" << ' '<< a; cout <<' '<<"adalah :"<<sinus<<"\n"; cout <<"Tekan Esc untuk keluar program"<<endl; return ; void hitung_cosinus(float a){ float cosinus; cosinus=cos(a); cout<<"\ncosinus dari angka" << ' '<< a; cout <<' '<<"adalah :"<<cosinus<<"\n"; cout <<"Tekan Esc untuk keluar program"<<endl; return ; void hitung_tangen (float a) { float tangen; tangen=tan(a);
cout<<"\ntangen dari angka" << ' '<< a; cout <<' '<<"adalah :"<<tangen<<"\n"; cout <<"Tekan Esc untuk keluar program"<<endl; return ; main(){ float a, x; char kar; cout<<"hitung Sinus, Cosinus dan Tangen" <<endl; cout<<"masukkan angkanya:";cin>>a; cout<<"\napa yang ingin anda cari? (1.Sinus 2.Cosinus 3.Tangen): "; cin>>x;endl; if(x==1) hitung_sinus(a); else if (x==2) hitung_cosinus(a); else if (x==3) hitung_tangen(a); else cout <<"\ntak ada dalam daftar, tekan Esc untuk keluar program"<<endl; for ( ; ;) { kar = getche();
if (kar == 27) break; Latihan 2 :; #include <iostream.h> #include <math.h> #include <conio.h> class trigonometri{ friend ostream& operator<<(ostream&, const trigonometri&); friend istream& operator>>(istream&, trigonometri&); public : trigonometri(); void hitung_cosinus(){hasil1=cos((angka*3,14)/180); void hitung_sinus(){hasil2=sin((angka*3,14)/180); void hitung_tangen(){hasil3=tan((angka*3,14)/180); private : int angka; float hasil1; float hasil2; float hasil3; ;
trigonometri::trigonometri(){ cout<<"program mencari trigonometri dari sebuah angka"<<endl; istream& operator>>(istream& in, trigonometri& masukan){ cout<<"masukkan angka : ";in >>masukan.angka; return in; ostream& operator<<(ostream& out, const trigonometri& keluaran){ out<<"sudut yang akan dikonversi : "<<keluaran.angka<<endl<<endl; out<<"dihitung dengan cosinus = "<<keluaran.hasil1<<endl; out<<"dihitung dengan sinus = "<<keluaran.hasil2<<endl; out<<"dihitung dengan tangen = "<<keluaran.hasil3<<endl; return out; main(){ trigonometri x; cin>>x; x.hitung_cosinus(); x.hitung_sinus(); x.hitung_tangen(); cout<<x; getch(); return 0;