max和min未定义
来源:百度知道 编辑:UC知道 时间:2024/05/21 06:18:17
#include <iostream>
#icnlude <algorithm>
using namespace std;
int main()
{
cout << "Please enter two number:";
int a,b;
cin >> a >> b;
cout << "a+b=" << a+b << "\n";
cout << "a-b=" << a-b << "\n";
cout << "axb=" << a*b << "\n";
cout << "(a+b)/2=" << (a+b)/2 << "\n";
cout << "|a-b|=" << abs(a-b) << "\n";
cout << "max of a and b is " << max(a, b)
cout << "min of a and b is " << min(a, b)
return 0;
}
编译提示error: max and min 未定义?这是为什么啊
问题解决了
原来是要把
#include <algorithm>-->#include "windef.h"
供大家参考
谢谢大家的回答
#icnlude <algorithm>
using namespace std;
int main()
{
cout << "Please enter two number:";
int a,b;
cin >> a >> b;
cout << "a+b=" << a+b << "\n";
cout << "a-b=" << a-b << "\n";
cout << "axb=" << a*b << "\n";
cout << "(a+b)/2=" << (a+b)/2 << "\n";
cout << "|a-b|=" << abs(a-b) << "\n";
cout << "max of a and b is " << max(a, b)
cout << "min of a and b is " << min(a, b)
return 0;
}
编译提示error: max and min 未定义?这是为什么啊
问题解决了
原来是要把
#include <algorithm>-->#include "windef.h"
供大家参考
谢谢大家的回答
对啊~~
你的max 和min就没有定义~~~
提示是对的~~
这样定义~~:
int max(int a, int b)
{
return a>b?a:b;
}
int min(int a, int b)
{
return a<b?a:b;
}
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
cout << "Please enter two number:";
int a,b;
cin >> a >> b;
cout << "a+b=" << a+b << "\n";
cout << "a-b=" << a-b << "\n";
cout << "axb=" << a*b << "\n";
cout << "(a+b)/2=" << (a+b)/2 << "\n";
cout << "|a-b|=" << abs(a-b) << "\n";
cout << "max of a and b is " << max(a, b);
cout << "min of a and b is " << min(a, b);