#G050. GESP level2 常用数学函数(绝对值函数、平方根函数、max函数、min函数)

GESP level2 常用数学函数(绝对值函数、平方根函数、max函数、min函数)

GESP level2 - 常用数学函数(绝对值函数、平方根函数、max函数、min函数)

  1. C++中,若要计算整数 -5 的绝对值,应使用以下哪个函数( ) {{ select(1) }}
  • abs()
  • fabs()
  • sqrt()
  • max()
  1. 执行以下代码后,输出结果是( )
    #include 
    #include 
    using namespace std;
    int main(){
    double num = 25.0;
    cout << sqrt(num);
    return 0;
    }
    
    {{ select(2) }}
  • 5
  • 5.0
  • 625
  • 0
  1. 在C++中,以下代码执行后的输出结果是( )
    #include 
    #include 
    using namespace std;
    int main(){
    int a = 10, b = 20;
    cout << max(a, b);
    return 0;
    }
    
    {{ select(3) }}
  • 10
  • 20
  • 30
  • 100
  1. 下列关于min函数的说法,错误的是( ) {{ select(4) }}
  • min函数用于返回两个数中的较小值
  • min函数只能比较整数
  • 使用min函数需要包含<algorithm>头文件
  • min(3.5, 2.8)的返回值是2.8
  1. 执行以下代码,输出结果是( )
    #include 
    #include 
    using namespace std;
    int main(){
    int num = -8;
    cout << abs(num);
    return 0;
    }
    
    {{ select(5) }}
  • -8
  • 8
  • 0
  • 8.0
  1. 以下代码执行后,输出的结果是( )
    #include 
    #include 
    using namespace std;
    int main(){
    double x = 5.5, y = 3.2;
    cout << min(x, y);
    return 0;
    }
    
    {{ select(6) }}
  • 5.5
  • 3.2
  • 2.3
  • 8.7
  1. 在判断一个大于1的整数n是否为质数的代码中,常使用sqrt()函数优化判断过程,以下代码横线处应填入( )
    #include 
    #include 
    using namespace std;
    bool isPrime(int n){
    if (n <= 1) return false;
    for (int i = 2; i <= ______; i++){
    if (n % i == 0) return false;
    }
    return true;
    }
    int main(){
    int num = 17;
    if (isPrime(num)) cout << num << "是质数";
    else cout << num << "不是质数";
    return 0;
    }
    
    {{ select(7) }}
  • n
  • n - 1
  • sqrt(n)
  • n / 2
  1. 执行下列代码,输出结果是( )
    #include 
    #include 
    using namespace std;
    int main(){
    int a = -10, b = 25;
    cout << abs(a) + sqrt(b);
    return 0;
    }
    
    {{ select(8) }}
  • 5
  • 15
  • 25
  • 35