Mathematical Function atan() cos() div() modf() sin() Explain By : M.R Bhatti
Danger zone 1 atan() In C programming atan() function computes the arc tangent(inverse tangent) of an argument. Function atan() takes single argument and returns the value in radians. Returned value of atan is of type double. Header File : Math.h Syntax : double atan(argument); * EXAMPLE * #include < stdio.h > #include < math.h > #define PI 3.141592654 void main () { float num ; double result ; printf ("Enter the parameter: "); scanf ("% f",& num ); result = atan ( num ); printf ("Inverse of tan(%.2f)=%.2f in radians", num , result ); /* ------ Converting radians to degree -------- */ result =( result *180)/ PI ; printf ("\ nInverse of tan(%.2f)=%.2f in degrees", num , result ); }
Danger zone 2 Output : Enter the parameter: 1 Inverse of cos(1.00)=0.79 in radians Inverse of cos(1.00)=45 in degrees
Danger zone 3 COS() In C programming, cos() function computes the cosine of an argument. Function cos() takes the value in radian and returns value in type double. Header file : Math.h Syntax : double cos(argument); * Example * #include < stdio.h > #include < math.h > #define PI 3.141592654 void main () { double arg , result ; printf ("Enter the argument in degrees: "); scanf ("% lf ",& arg ); /*------ Converting to radian --------*/ arg =( arg * PI )/180; result = cos ( arg ); printf ("cos of %.2lf radian = %.2lf", arg , result ); }
Danger zone 2 Output : Enter the argument in degrees: 30 Cos of 0.52 radian = 0.87
Danger zone 4 Div() Integer Division In the C Programming Language, the div function divides numerator by denominator . Based on that division calculation, the div function returns a structure containing two members - quotient and remainder. Header file : #include <stdlib.h> Syntax : div_t div(int numerator, int denominator); Parameters or Arguments Numerator : The value that is divided by denominator in the division calculation. Denominator : The value divided into numerator in the division calculation. So if numerator is 10 and denominator is 2, then 10 would be divided by 2. Returns The div function returns a structure with the resulting quotient and remainder based on the division calculation.
Danger zone 5 *Example* #include < stdio.h > #include <stdlib.h> void main () { div_t output; output = div(27, 4); printf("Quotient part of (27/ 4) = %d\n", output.quot ); printf("Remainder part of (27/4) = %d\n", output.rem ); output = div(27, 3); printf("Quotient part of (27/ 3) = %d\n", output.quot ); printf("Remainder part of (27/3) = %d\n", output.rem ); getch(); }
Danger zone 2 Output : Quotient part of (27/4) = 6 Remainder part of (27/4) =3 Quotient part of (27/3) = 9 Remainder part of (27/3) = 0
In C programming, sin() function computes the sine of an argument. Function sin() takes the value in radian and returns value in type double. Header file : Math.h Syntax : double sin (argument); *Example* #include < stdio.h > #include < math.h > #define PI 3.141592654 void main () { double arg , result ; printf ("Enter the argument in degrees: "); scanf ("%lf",& arg ); /*------ Converting to radians --------*/ arg =( arg * PI )/180; result = sin ( arg ); printf ("sin(%.2lf) [In radian] = %.2lf", arg , result ); } Sin()
Danger zone 2 Output : Enter the argument in degrees: 30cos(0.52) [In radian] = 0.50