home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / math / trig.c < prev   
Encoding:
C/C++ Source or Header  |  1988-10-28  |  1.7 KB  |  63 lines

  1. /* TRIG.C illustrates trignometric functions including:
  2.  *    cos          cosh           acos
  3.  *    sin          sinh           asin
  4.  *    tan          tanh           atan          atan2
  5.  */
  6.  
  7. #include <math.h>
  8. #include <float.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. main()
  13. {
  14.     double x, rx, y;
  15.  
  16.     do
  17.     {
  18.         printf( "\nEnter a real number between 1 and -1: " );
  19.         scanf( "%lf", &x );
  20.     } while( (x > 1.0) || (x < -1.0) );
  21.  
  22.     printf("\nFunction\tResult for %2.2f\n\n", x );
  23.     if( (x <= 1.0) && (x >= -1.0) )
  24.     {
  25.         printf( "acos\t\t%2.2f\n", acos( x ) );
  26.         printf( "asin\t\t%2.2f\n", asin( x ) );
  27.     }
  28.     if( (rx = cos( x )) && (errno != ERANGE) )
  29.         printf( "cos\t\t%2.2f\n", rx );
  30.     else
  31.         errno = 0;
  32.     if( (rx = sin( x )) && (errno != ERANGE) )
  33.         printf( "sin\t\t%2.2f\n", rx );
  34.     else
  35.         errno = 0;
  36.     if( (rx = cosh( x )) && (errno != ERANGE) )
  37.         printf( "cosh\t\t%2.2f\n", rx );
  38.     else
  39.         errno = 0;
  40.     if( (rx = sinh( x )) && (errno != ERANGE) )
  41.         printf( "sinh\t\t%2.2f\n", rx );
  42.     else
  43.         errno = 0;
  44.  
  45.     printf( "\nEnter a real number of any size: " );
  46.     scanf( "%lf", &x );
  47.     printf("\nFunction\tResult for %2.2f\n\n", x );
  48.     printf( "atan\t\t%2.2f\n", atan( x ) );
  49.     if( (rx = tan( x )) && (errno != ERANGE) )
  50.         printf( "tan\t\t%2.2f\n", rx );
  51.     else
  52.         errno = 0;
  53.     printf( "tanh\t\t%2.2f\n", tanh( x ) );
  54.  
  55.     printf( "\nEnter another real number of any size: " );
  56.     scanf( "%lf", &y );
  57.     printf("\nFunction\tResult for %2.2f and %2.2f\n\n", x, y );
  58.     if( rx = atan2( x, y ) )
  59.         printf( "atan2\t\t%2.2f\n", rx );
  60.     else
  61.         errno = 0;
  62. }
  63.