cos wird in C über math.h, bzw. in C++ über cmath eingebunden.
Die Funktion errechnet den Cosinus eines Winkels. Die Rückgabe liegt im Bereich zwischen -1 und 1.
double cos ( double x ); float cos ( float x ); /* nur in C++ */ long double cos ( long double x ); /* nur in C++ */ long double cosl( long double x ); float cosf( float x );
x: Winkel (im Bogenmaß), dessen Cosinus berechnet werden soll.
Return Value: Berechneter Cosinus.
Der Winkel muss im Bogenmaß (0 bis 2*π) angegeben werden, nicht im Grad (0 bis 360) oder Neugrad (0 bis 400).
#include <stdlib.h> // für EXIT_SUCCESS #include <math.h> // für sin, cos #include <stdio.h> // für printf() #define PI 3.141592654 int main( void ) { double radian, degree = 90; double x, y; radian = degree / 180 * PI; // Grad in Radial umrechnen y = sin( radian ); x = cos( radian ); printf( "%f Grad: x-Laenge: %f, y-Laenge: %f\n", degree, x, y ); return EXIT_SUCCESS; }
Ausgabe:
90.000000 Grad: x-Laenge: 1.000000, y-Laenge: -0.000000
In C++ wird diese Funktion mit einem ValueArray-Template überladen.