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