c++中math庫如何使用-創(chuàng)新互聯(lián)

這期內(nèi)容當中小編將會給大家?guī)碛嘘P(guān)c++中math庫如何使用,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

成都做網(wǎng)站、成都網(wǎng)站建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)介紹好的網(wǎng)站是理念、設(shè)計和技術(shù)的結(jié)合。創(chuàng)新互聯(lián)擁有的網(wǎng)站設(shè)計理念、多方位的設(shè)計風格、經(jīng)驗豐富的設(shè)計團隊。提供PC端+手機端網(wǎng)站建設(shè),用營銷思維進行網(wǎng)站設(shè)計、采用先進技術(shù)開源代碼、注重用戶體驗與SEO基礎(chǔ),將技術(shù)與創(chuàng)意整合到網(wǎng)站之中,以契合客戶的方式做到創(chuàng)意性的視覺化效果。

abs

原型:extern int abs(int x);
用法:#include 
功能:求整數(shù)x的絕對值
說明:計算|x|, 當x不為負時返回x,否則返回-x
舉例:
      
      #include 
      #include 

      main()
      {
        int x;
        clrscr();        // clear screen
        x=-5;
        printf("|%d|=%d\n",x,abs(x));
        x=0;
        printf("|%d|=%d\n",x,abs(x));
        x=+5;
        printf("|%d|=%d\n",x,abs(x));
        getchar();
        return 0;
      }
相關(guān)函數(shù):fabs

acos
原型:extern float acos(float x);
用法:#include 
功能:求x(弧度表示)的反余弦值
說明:x的定義域為[-1.0,1.0],值域為[0,π]。
舉例:
      
      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=0.32;
        printf("acos(%.2f)=%.4f",x,acos(x));
        getchar();
        return 0;
      }
相關(guān)函數(shù):asin,atan,atan2,sin,cos,tan

asin

原型:extern float asin(float x);
用法:#include 
功能:求x(弧度表示)的反正弦值
說明:x的定義域為[-1.0,1.0],值域為[-π/2,+π/2]。
舉例:

      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=0.32;
        printf("asin(%.2f)=%.4f",x,asin(x));
        getchar();
        return 0;
      }
相關(guān)函數(shù):acos,atan,atan2,sin,cos,tan

atan

原型:extern float atan(float x);
用法:#include 
功能:求x(弧度表示)的反正切值
說明:值域為(-π/2,+π/2)。
舉例:

      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=0.32;
        printf("atan(%.2f)=%.4f",x,atan(x));
        getchar();
        return 0;
      }
相關(guān)函數(shù):asin,acos,atan2,sin,cos,tan

atan2

原型:extern float atan2(float y, float x);
用法:#include 
功能:求y/x(弧度表示)的反正切值
說明:值域為(-π/2,+π/2)。
舉例:

      #include 
      #include 
      main()
      {
        float x,y;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=0.064;
        y=0.2;
        printf("atan2(%.3f,%.2f)=%.4f",y,x,atan2(y,x));
        getchar();
        return 0;
      }
相關(guān)函數(shù):asin,acos,atan,sin,cos,tan

ceil

原型:extern float ceil(float x);
用法:#include 
功能:求不小于x的最小整數(shù)
說明:返回x的上限,如74.12的上限為75,-74.12的上限為-74。返回值為float類型。
舉例:

      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=74.12;
        printf("ceil(%.2f)=%.0f\n",x,ceil(x));
        x=-74.12;
        printf("ceil(%.2f)=%.0f\n",x,ceil(x));
        getchar();
        return 0;
      }
相關(guān)函數(shù):floor

cos

原型:extern float cos(float x);
用法:#include 
功能:求x(弧度表示)的余弦值
說明:返回值在[-1.0,1.0]之間。
舉例:

      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=PI/4.;
        printf("cos(%.4f)=%.4f\n",x,cos(x));
        getchar();
        return 0;
      }
相關(guān)函數(shù):asin,acos,atan,atan2,sin,tan

cosh

原型:extern float cosh(float x);
用法:#include 
功能:求x的雙曲余弦值
說明:cosh(x)=(e^x+e^(-x))/2
舉例:

      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=PI/4.;
        printf("cosh(%.4f)=%.4f\n",x,cosh(x));
        getchar();
        return 0;
      }
相關(guān)函數(shù):sinh,tanh

exp

原型:extern float exp(float x);
用法:#include 
功能:求e的x次冪
說明:e=2.718281828...
舉例:

      #include 
      #include 
      main()
      {
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        printf("e=%f\n",exp(1.0));
        getchar();
        return 0;
      }
相關(guān)函數(shù):無

fabs

原型:extern float fabs(float x);
用法:#include 
功能:求浮點數(shù)x的絕對值
說明:計算|x|, 當x不為負時返回x,否則返回-x
舉例:

      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=-74.12;
        printf("|%f|=%f\n",x,fabs(x));
        x=0;
        printf("|%f|=%f\n",x,fabs(x));
        x=74.12;
        printf("|%f|=%f\n",x,fabs(x));
        getchar();
        return 0;
      }
相關(guān)函數(shù):abs

floor

原型:extern float floor(float x);
用法:#include 
功能:求不大于x的最達整數(shù)
說明:返回x的下限,如74.12的下限為74,-74.12的下限為-75。返回值為float類型。
舉例:

      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=74.12;
        printf("floor(%.2f)=%.0f\n",x,floor(x));
        x=-74.12;
        printf("floor(%.2f)=%.0f\n",x,floor(x));
        getchar();
        return 0;
      }
相關(guān)函數(shù):ceil

fmod

原型:extern float fmod(float x, float y);
用法:#include 
功能:計算x/y的余數(shù)
說明:返回x-n*y,符號同y。n=[x/y](向離開零的方向取整)
舉例:

      #include 
      #include 
      main()
      {
        float x,y;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=74.12;
        y=6.4;
        printf("74.12/6.4: %f\n",fmod(x,y));       
        x=74.12;
        y=-6.4;
        printf("74.12/(-6.4): %f\n",fmod(x,y));       
        getchar();
        return 0;
      }
相關(guān)函數(shù):無

frexp

原型:extern float frexp(float x, int *exp);
用法:#include 
功能:把浮點數(shù)x分解成尾數(shù)和指數(shù)。
說明:x=m*2^exp,m為規(guī)格化小數(shù)。返回尾數(shù)m,并將指數(shù)存入exp中。
舉例:

      #include 
      #include 
      main()
      {
        float x;
        int exp;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=frexp(64.0,&exp);
        printf("64=%.2f*2^%d",x,exp);
        getchar();
        return 0;
      }
相關(guān)函數(shù):ldexp,modf

hypot

原型:extern float hypot(float x, float y);
用法:#include 
功能:對于給定的直角三角形的兩個直角邊,求其斜邊的長度。
說明:返回斜邊值。
舉例:

      #include 
      #include 
      main()
      {
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        printf("3^2+4^2=%.0f^2\n",hypot(3.,4.));
        printf("3.2^2+4.3^2=%.2f^2",hypot(x,y));
        getchar();
        return 0;
      }
相關(guān)函數(shù):frexp,ldexp

ldexp

原型:extern float ldexp(float x, int exp);
用法:#include 
功能:裝載浮點數(shù)。
說明:返回x*2^exp的值。
舉例:

      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=ldexp(1.0,6); // 1.0*2^6
        printf("2^6=%.2f",x);
        getchar();
        return 0;
      }
相關(guān)函數(shù):frexp,modf

log

原型:extern float log(float x);
用法:#include 
功能:計算x的自然對數(shù)。
說明:x的值應(yīng)大于零。
舉例:

      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        printf("ln(e)=%f\n", log(M_E)); // M_E is 2.71828..., defined in math.h
        getchar();
        return 0;
      }
相關(guān)函數(shù):log10

log10

原型:extern float log10(float x);
用法:#include 
功能:計算x的常用對數(shù)。
說明:x的值應(yīng)大于零。
舉例:

      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        printf("lg(5)=%f\n", log10(5.0));
        getchar();
        return 0;
      }
相關(guān)函數(shù):log

modf

原型:extern float modf(float num, float *i);
用法:#include 
功能:將浮點數(shù)num分解成整數(shù)部分和小數(shù)部分。
說明:返回小數(shù)部分,將整數(shù)部分存入*i所指內(nèi)存中。
舉例:

      #include 
      #include 
      main()
      {
        float x, i;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=modf(-74.12,&i);
        printf("-74.12=%.0f+(%.2f)",i,x);
        getchar();
        return 0;
      }
相關(guān)函數(shù):frexp,ldexp

pow10

原型:extern float pow10(float x);
用法:#include 
功能:計算10的x次冪。
說明:相當于pow(10.0,x)。
舉例:

      #include 
      #include 
      main()
      {
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        printf("10^3.2=%f\n",pow10(3.2));
        printf("10^3.2=%f",pow(10,3.2));
        getchar();
        return 0;
      }
相關(guān)函數(shù):pow

pow

原型:extern float pow(float x, float y);
用法:#include 
功能:計算x的y次冪。
說明:x應(yīng)大于零,返回冪指數(shù)的結(jié)果。
舉例:

      #include 
      #include 
      main()
      {
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        printf("4^5=%f",pow(4.,5.));
        getchar();
        return 0;
      }
相關(guān)函數(shù):pow10

sin

原型:extern float sin(float x);
用法:#include 
功能:計算x(弧度表示)的正弦值。
說明:x的值域為[-1.0,1.0]。
舉例:

      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=M_PI/2;        // M_PI=PI=3.14159265..., defined in math.h
        printf("sin(PI/2)=%f",sin(x));
        getchar();
        return 0;
      }
相關(guān)函數(shù):asin,acos,atan,atan2,cos,tan

sinh

原型:extern float sinh(float x);
用法:#include 
功能:計算x(弧度表示)的雙曲正弦值。
說明:sinh(x)=(e^x-e^(-x))/2。
舉例:

      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=PI/4.;
        printf("sinh(%.4f)=%.4f\n",x,sinh(x));
        getchar();
        return 0;
      }  
相關(guān)函數(shù):cosh,tanh

sqrt

原型:extern float sqrt(float x);
用法:#include 
功能:計算x的平方根。
說明:x應(yīng)大于等于零。
舉例:

      #include 
      #include 
      main()
      {
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        printf("sqrt(2000)=%f",sqrt(2000.0));
        getchar();
        return 0;
      }     
相關(guān)函數(shù):無

tan

原型:extern float tan(float x);
用法:#include 
功能:計算x(弧度表示)的正切值。
說明:返回x的正切值。
舉例:

      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=M_PI/4;        // M_PI=PI=3.14159265..., defined in math.h
        printf("tan(PI/4)=%f",tan(x));
        getchar();
        return 0;
      }
相關(guān)函數(shù):asin,acos,atan,atan2,sin,cos

tanh

原型:extern float tanh(float x);
用法:#include 
功能:求x的雙曲正切值
說明:tanh(x)=(e^x-e^(-x))/(e^2+e^(-x))
舉例:

      #include 
      #include 
      main()
      {
        float x;
        clrscr();        // clear screen
        textmode(0x00); // 6 lines per LCD screen
        x=PI/4.;
        printf("tanh(%.4f)=%.4f\n",x,tanh(x));
        getchar();
        return 0;
      }

上述就是小編為大家分享的c++中math庫如何使用了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

當前題目:c++中math庫如何使用-創(chuàng)新互聯(lián)
標題路徑:http://bm7419.com/article12/dpcogc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、網(wǎng)站設(shè)計公司企業(yè)建站、手機網(wǎng)站建設(shè)、建站公司、自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護公司