按照用途分类
按照编程范式分类
按照编译方式分类
1// std::max函数:用于返回两个值中的较大值
2#include <iostream>
3#include <algorithm> // std::max
4
5int main() {
6 int a = 10, b = 20;
7 std::cout << "Max: " << std::max(a, b) << std::endl; // 输出20
8 return 0;
9}1// std::min函数:用于返回两个值中的较小值
2#include <iostream>
3#include <algorithm> // std::min
4
5int main() {
6 int a = 10, b = 20;
7 std::cout << "Min: " << std::min(a, b) << std::endl; // 输出10
8 return 0;
9}1// std::ceil:向上取整,即返回大于或等于参数的最小整数。
2#include <iostream>
3#include <cmath> // std::ceil
4
5int main() {
6 double value = 3.14;
7 std::cout << "Ceil: " << std::ceil(value) << std::endl; // 输出4
8 return 0;
9}1// std::floor:向下取整,即返回小于或等于参数的最大整数。
2#include <iostream>
3#include <cmath> // std::floor
4
5int main() {
6 double value = 3.14;
7 std::cout << "Floor: " << std::floor(value) << std::endl; // 输出3
8 return 0;
9}1// std::round:四舍五入取整。
2#include <iostream>
3#include <cmath> // std::round
4
5int main() {
6 double value = 3.5;
7 std::cout << "Round: " << std::round(value) << std::endl; // 输出4
8 return 0;
9}1// std::trunc:截断小数部分,即返回数值的整数部分。
2#include <iostream>
3#include <cmath> // std::trunc
4
5int main() {
6 double value = 3.14;
7 std::cout << "Trunc: " << std::trunc(value) << std::endl; // 输出3
8 return 0;
9}1#include <iostream>
2#include <cmath> // std::abs
3
4int main() {
5 int value = -10;
6 std::cout << "Abs: " << std::abs(value) << std::endl; // 输出10
7 return 0;
8}1#include <iostream>
2#include <cmath> // std::sqrt
3
4int main() {
5 double value = 16.0;
6 std::cout << "Sqrt: " << std::sqrt(value) << std::endl; // 输出4
7 return 0;
8}1#include <iostream>
2#include <cmath> // std::pow
3
4int main() {
5 double base = 2.0, exponent = 3.0;
6 std::cout << "Pow: " << std::pow(base, exponent) << std::endl; // 输出8
7 return 0;
8}1#include <iostream>
2#include <cstdlib> // std::rand, std::srand
3#include <ctime> // std::time
4
5int main() {
6 std::srand(static_cast<unsigned int>(std::time(nullptr))); // 使用当前时间作为随机数种子
7
8 for (int i = 0; i < 5; i++) {
9 std::cout << "Random number: " << std::rand() << std::endl;
10 }
11
12 return 0;
13}