⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sa1604.c

📁 数十个C语言的代码
💻 C
字号:
#include <math.h>  //math.h头文件必须包含
#include <stdio.h>

void main()
{
   double pi = 3.1415926535;
   double x, y;

   int    ix,iy;
   long   lx,ly;
   double dx,dy;

   double question , answer;

   //以下三角函数的参数均为弧度值

   //三角函数sin 和cos
   printf("sin,cos\n");
   x = pi / 2;
   y = sin( x );
   printf( "sin( %f ) = %f\n", x, y );
   y = cos( x );
   printf( "cos( %f ) = %f\n", x, y );
   printf("\n");
   getch();

   //三角函数arcsin 和arccos
   printf("asin and acos\n");
   printf( "Enter a real number between -1 and 1: " );
   scanf( "%lf", &x );
   y = asin( x );
   printf( "Arcsine of %f = %f\n", x, y );
   y = acos( x );
   printf( "Arccosine of %f = %f\n", x, y );
   printf("\n");
   getch();

   //三角函数tg
   printf("tan\n");
   x = tan( pi / 4 );
   printf( "tan( %f ) = %f\n", x, y );
   printf("\n");
   getch();

   //求绝对值函数
   //abs对int型数求绝对值,labs对long型数求绝对值,fabs对float,double型数求绝对值,
   printf("abs ,labs and fabs\n");
   ix = -4, iy;
   lx = -41567L, ly;
   dx = -3.141593, dy;
   iy = abs( ix );
   printf( "The absolute value of %d is %d\n", ix, iy);
   ly = labs( lx );
   printf( "The absolute value of %ld is %ld\n", lx, ly);
   dy = fabs( dx );
   printf( "The absolute value of %f is %f\n", dx, dy );
   printf("\n");
   getch();

   //求平方根函数sqrt
   printf("sqrt\n");
   question = 45.35;
   answer = sqrt( question );
   if( question < 0 )
      printf( "Error: sqrt returns %.2f\n", answer );
   else
      printf( "The square root of %.2f is %.2f\n", question, answer );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -