所谓系统函数就是前辈们已经实现好的代码,需要的时候直接调用就可以了。比如我们之前用过的abs() ,ceil(),floor()等,这些写好的函数放在cmath库里,用的时候要先include进来。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /****************************************************************************** system function author: Thin Rabbit date: 2021-5-22 *******************************************************************************/ #include <iostream> #include <cmath> using namespace std; int main() { int a=-5; float b=3.14; cout<<abs(a)<<endl; //Returns the absolute value of x: |x| cout<<ceil(b)<<endl; //returning the smallest integral value that is not less than x cout<<floor(b)<<endl; //Rounds x downward, returning the largest integral value that is not greater than x cout<<pow(a,2)<<endl; //Returns base raised to the power exponent cout<<sqrt(9)<<endl; //Returns the square root of x return 0; } |
备注:
double pow(double x, double y) 返回 x 的 y 次幂,即 xy。 (power)
double sqrt(double x) 返回 x 的平方根 (square root)