C27-数学函数
原题链接:38471.note12025-08-18 18:10:51
发布于:江苏
一、常用数据函数
二、课堂案例
1. 判断整数
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int t = sqrt(n);
if (t*t == n){
cout << "yes";
}
else {
cout << "no";
}
return 0;
}
2. 小数绝对值
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
int n;
cin >> n;
// cout << sqrt(n) << endl;
cout << fixed << setprecision(2) << sqrt(n) << endl;
printf("%.2lf", sqrt(n));
cout << fabs(-3.14) << endl;
return 0;
}
3. pow的返回值类型
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;
int main()
{
// cout << 10/0 << endl;
cout << 10/0.0 << endl; //infinity
// cout << typeid(pow(2, 10)).name();
bool a = 1;
cout << typeid(a).name();
return 0;
}
这里空空如也
有帮助,赞一个