#include <algorithm>//引入max、min命名空间 #include <iostream> using namespace std; int main() { int a, b,c; cin>>a>>b>>c; // 使用max函数找到最大值 int m_max = max({a, b, c}); // C++11支持的初始化列表 int m_min = min({a,b,c}); cout << "The maximum number is : " << m_max << '\n'; cout << "The minimum number is : " << m_min << '\n'; return 0; } // 64 位输出请用 printf("%lld")
- 计算最大值和最小值:使用std::max函数找到三个数中的最大值。使用std::min函数找到三个数中的最小值。这里使用了C++11的初始化列表语法{a, b, c},可以直接对三个数进行操作。