1.abs(計算整型數的絕對值)
相關函數:
labs, fabs
表頭文件:
#include<math.h>
定義函數:
int abs (int j)
函數說明:
abs()用來計算參數j的絕對值,然後將結果返回。
返回值:
返回參數j的絕對值結果。
范例:
#include <stdio.h>
#include <math.h>
main()
{
int answer;
answer = abs(-12);
printf("|-12| = %d\n", answer);
}
2.acos(取反余弦函數數值)
相關函數:
asin , atan , atan2 , cos , sin , tan
表頭文件:
#include <math.h>
定義函數:
double acos (double x);
函數說明:
acos()用來計算參數x的反余弦值,然後將結果返回。參數x范圍為-1至1之間,超過此范圍則會失敗。
返回值:
返回0至PI之間的計算結果,單位為弧度,在函數庫中角度均以弧度來表示。
錯誤代碼:
EDOM參數x超出范圍。
范例:
#include <stdio.h>
#include <math.h>
main ()
{
double angle;
angle = acos(0.5);
printf("angle = %f\n", angle);
}
3.asin(取反正弦函數值)
相關函數:
acos , atan , atan2 , cos , sin , tan
表頭文件:
#include <math.h>
定義函數:
double asin (double x)
函數說明:
asin()用來計算參數x的反正弦值,然後將結果返回。參數x范圍為-1至1之間,超過此范圍則會失敗。
返回值:
返回-PI/2之PI/2之間的計算結果。
錯誤代碼:
EDOM參數x超出范圍
使用GCC編譯時請加入-lm
范例:
#include <stdio.h>
#include<math.h>
main()
{
double angle;
angle = asin (0.5);
printf("angle = %f\n",angle);
}
4.atan(取反正切函數值)
相關函數:
acos,asin,atan2,cos,sin,tan
表頭文件:
#include<math.h>
定義函數:
double atan(double x);
函數說明:
atan()用來計算參數x的反正切值,然後將結果返回。
返回值:
返回-PI/2至PI/2之間的計算結果。
范例:
#include <stdio.h>
#include<math.h>
main()
{
double angle;
angle =atan(1);
printf("angle = %f\n",angle);
}
5.atan2(取得反正切函數值)
相關函數:
acos,asin,atan,cos,sin,tan
表頭文件:
#include<math.h>
定義函數:
double atan2(double y,double x);
函數說明:
atan2()用來計算參數y/x的反正切值,然後將結果返回。
返回值:
返回-PI/2 至PI/2 之間的計算結果。
范例:
#include <stdio.h>
#include<math.h>
main()
{
double angle;
angle = atan2(1,2);
printf("angle = %f\n", angle);
}
6.ceil(取不小於參數的最小整型數)
相關函數:
fabs
表頭文件:
#include <math.h>
定義函數:
double ceil (double x);
函數說明:
ceil()會返回不小於參數x的最小整數值,結果以double形態返回。
返回值:
返回不小於參數x的最小整數值。
附加說明
使用GCC編譯時請加入-lm。
范例:
#include <stdio.h>
#include<math.h>
main()
{
double value[ ]={4.8,1.12,-2.2,3,0};
int i;
for (i=0;value[i]!=0;i++)
printf("%f>=%f\n",value[i],ceil(value[i]));
}
6.cos(取余玄函數值)
相關函數:
acos,asin,atan,atan2,sin,tan
表頭文件:
#include<math.h>
定義函數:
double cos(double x);
函數說明:
cos()用來計算參數x 的余玄值,然後將結果返回。
返回值:
返回-1至1之間的計算結果。
附加說明:
使用GCC編譯時請加入-lm。
范例:
#include <stdio.h>
#include<math.h>
main()
{
double answer = cos(3.14/6);
printf("cos (0.5) = %f\n",answer);
}
7.cosh(取雙曲線余玄函數值)
相關函數:
sinh,tanh
表頭文件:
#include<math.h>
定義函數:
double cosh(double x);
函數說明:
cosh()用來計算參數x的雙曲線余玄值,然後將結果返回。數學定義式為:(exp(x)+exp(-x))/2。
返回值:
返回參數x的雙曲線余玄值。
附加說明:
使用GCC編譯時請加入-lm。
范例:
#include <stdio.h>
#include<math.h>
main()
{
double answer = cosh(0.5);
printf("cosh(0.5) = %f\n",answer);
}
8.exp(計算指數)
相關函數:
log,log10,pow
表頭文件:
#include<math.h>
定義函數:
double exp(double x);
函數說明:
exp()用來計算以e為底的x次方值,即ex值,然後將結果返回。
返回值:
返回e的x次方計算結果。
附加說明:
使用GCC編譯時請加入-lm。
范例:
#include <stdio.h>
#include<math.h>
main()
{
double answer;
answer = exp (10);
printf("e^10 =%f\n", answer);
}
9.frexp(將浮點型數分為底數與指數)
相關函數:
ldexp,modf
表頭文件:
#include<math.h>
定義函數:
double frexp( double x, int *exp);
函數說明:
frexp()用來將參數x 的浮點型數切割成底數和指數。底數部分直接返回,指數部分則借參數exp 指針返回,將返回值乘以2 的exp次方即為x的值。
返回值:
返回參數x的底數部分,指數部分則存於exp指針所指的地址。
附加說明:
使用GCC編譯時請加入-lm。
范例:
#include <stdio.h>
#include <math.h>
main()
{
int exp;
double fraction,i;
fraction = frexp (1024,&exp);
i=ldexp(fraction,exp);
printf("exp = %d\n",exp);
printf("fraction = %f\n", fraction);
printf("i=%f",i);
}
10.ldexp(計算2的次方值)
相關函數:
frexp
表頭文件:
#include<math.h>
定義函數:
double ldexp(double x,int exp);
函數說明:
ldexp()用來將參數x乘上2的exp次方值,即x*2exp。
返回值:
返回計算結果。
附加說明:
使用GCC編譯時請加入-lm。
范例:
/* 計算3*(2^2)=12 */
#include <stdio.h>
#include<math.h>
main()
{
int exp;
double x,answer;
answer = ldexp(3,2);
printf("3*2^(2) = %f\n",answer);
}
11.log(計算以e 為底的對數值)
相關函數:
exp,log10,pow
表頭文件:
#include <math.h>
定義函數:
double log (double x);
函數說明:
log()用來計算以e為底的x 對數值,然後將結果返回。
返回值:
返回參數x的自然對數值。
錯誤代碼:
EDOM 參數x為負數,ERANGE 參數x為零值,零的對數值無定義。
附加說明:
使用GCC編譯時請加入-lm。
范例
#include <stdio.h>
#include <math.h>
main()
{
double answer;
answer = log (100);
printf("log(100) = %f\n",answer);
}
12.log10(計算以10 為底的對數值)
相關函數:
exp,log,pow
表頭文件:
#include<math.h>
定義函數:
double log10(double x);
函數說明:
log10()用來計算以10為底的x對數值,然後將結果返回。
返回值:
返回參數x以10為底的對數值。
錯誤代碼
EDOM參數x為負數。RANGE參數x為零值,零的對數值無定義。
附加說明
使用GCC編譯時請加入-lm。
范例:
#include <stdio.h>
#include <math.h>
main()
{
double answer;
answer = log10(100);
printf("log10(100) = %f\n",answer);
}
查看本欄目
13.pow(計算次方值)
相關函數:
exp,log,log10
表頭文件:
#include<math.h>
定義函數:
double pow(double x,double y);
函數說明:
pow()用來計算以x為底的y次方值,即xy值,然後將結果返回。
返回值:
返回x的y次方計算結果。
錯誤代碼:
EDOM 參數x為負數且參數y不是整數。
附加說明:
使用GCC編譯時請加入-lm。
范例:
#include <stdio.h>
#include <math.h>
main()
{
double answer;
answer =pow(2,10);
printf("2^10 = %f\n", answer);
}
14.sin(取正玄函數值)
相關函數:
acos,asin,atan,atan2,cos,tan
表頭文件:
#include<math.h>
定義函數:
double sin(double x);
函數說明:
sin()用來計算參數x的正玄值,然後將結果返回。
返回值:
返回-1 至1之間的計算結果。
附加說明
使用GCC編譯時請加入-lm。
#include <stdio.h>
#include <math.h>
main()
{
double answer = sin (0.5);
printf("sin(0.5) = %f\n",answer);
}
15.sinh(取雙曲線正玄函數值)
相關函數:
cosh,tanh
表頭文件:
#include<math.h>
定義函數:
double sinh( double x);
函數說明:
sinh()用來計算參數x的雙曲線正玄值,然後將結果返回。數學定義式為:(exp(x)-exp(-x))/2。
返回值:
返回參數x的雙曲線正玄值。
附加說明:
使用GCC編譯時請加入-lm。
范例:
#include <stdio.h>
#include <math.h>
main()
{
double answer = sinh (0.5);
printf("sinh(0.5) = %f\n",answer);
}
16.sqrt(計算平方根值)
相關函數:
hypotq
表頭文件:
#include<math.h>
定義函數:
double sqrt(double x);
函數說明:
sqrt()用來計算參數x的平方根,然後將結果返回。參數x必須為正數。
返回值:
返回參數x的平方根值。
錯誤代碼:
EDOM 參數x為負數。
附加說明:
使用GCC編譯時請加入-lm。
范例:
/* 計算200的平方根值*/
#include <stdio.h>
#include <math.h>
main()
{
double root;
root = sqrt (200);
printf("answer is %f\n",root);
}
17.tan(取正切函數值)
相關函數:
atan,atan2,cos,sin
表頭文件:
#include <math.h>
定義函數:
double tan(double x);
函數說明:
tan()用來計算參數x的正切值,然後將結果返回。
返回值:
返回參數x的正切值。
附加說明:
使用GCC編譯時請加入-lm。
范例:
#include <stdio.h>
#include <math.h>
main()
{
double answer = tan(0.5);
printf("tan (0.5) = %f\n",answer);
}
18.tanh(取雙曲線正切函數值)
相關函數:
cosh,sinh
表頭文件:
#include<math.h>
定義函數:
double tanh(double x);
函數說明:
tanh()用來計算參數x的雙曲線正切值,然後將結果返回。數學定義式為:sinh(x)/cosh(x)。
返回值:
返回參數x的雙曲線正切值。
附加說明:
使用GCC編譯時請加入-lm。
范例:
#include <stdio.h>
#include <math.h>
main()
{
double answer = tanh(0.5);
printf("tanh(0.5) = %f\n",answer);
}
本文出自 “LinuxQt濟南高新區” 博客,請務必保留此出處http://qtlinux.blog.51cto.com/3052744/960627