數學函式庫裡的函式

今天要來介紹C++裡面的數學函式庫裡的函式
使用,只要載入include<cmath>就可以使用囉~真是太棒了~
來瞧一瞧有怎樣的函式可以使用呀^^
天花板函式ceil(n)
地板函式floor(n)
絕對零度的絕對值fabs(n)
一除剩下多少的餘數函式fmod(n,m)
複利比原子彈的力量大的次方函式pow(n,m)
根號乘以十的開根號函式sqrt(n)
瞧一瞧範例吧XDD

#include <iostream>
#include <cstdlib>
#include <cmath> 
using namespace std;

int main()
{
    
    cout << "最接近且大於3.14的整數: " << ceil( 3.14 ) <<endl; 
    cout << "最接近且小於3.14的整數: " << floor(3.14) << endl;
    cout << "-1的絕對值: "  << fabs(-1) <<endl;
    cout << "7除以4的餘數:" << fmod(7.0,4.0) <<endl; 
    cout << "2的10次方:" << pow(2.0,10.0) << endl;
    cout << "100開根號: "<< sqrt(100) <<endl; 
    
    system("pause");
    return 0;

}



留言