ManbaDF99

C++中有两个库函数下有对应的求绝对值的函数:

  1. #include<stdlib.h>内,有abs()函数,可以对整型变量求绝对值。示例如下:
    #include<iostream>
    #include<stdlib.h>
    using namespace std;
    int main()
    {
        int a=-1;
        cout<<abs(a);
        return 0;
    }

    输出即为a的绝对值1。

  2. #include<math.h>内,有fabs()函数,可以对浮点型变量求绝对值。示例如下:
    #include<iostream>
    #include<math.h>
    using namespace std;
    int main()
    {
        int a=-1;
        cout<<fabs(a);
        return 0;
    }

     

分类:

技术点:

相关文章:

  • 2021-12-07
  • 2022-12-23
  • 2021-08-01
  • 2021-09-27
  • 2022-12-23
  • 2021-10-19
  • 2021-12-22
猜你喜欢
  • 2021-07-27
  • 2022-02-15
  • 2022-12-23
  • 2021-08-13
  • 2021-11-21
  • 2022-01-26
  • 2021-12-19
相关资源
相似解决方案