求两个整数中的较大者

img


请问这段代码哪里出现了问题,为什么一运行最上面就出现一个c的值?

该回答引用GPTᴼᴾᴱᴺᴬᴵ

#include <iostream>
#include <math.h>
using namespace std;

int max(int a, int b) {
int c;
if (a > b) {
c = a;
} else {
c = b;
}
return c;
}

int main() {
int a, b, c;
cout << "a=";
cin >> a;
cout << "b=";
cin >> b;
c = max(a, b);
cout << "c=" << c << endl;
return 0;
}



第7行删掉,这时候a和b还没有输入呢,你判断啥大小
然后max函数太罗嗦,只需要:

int max(int a,int b)
{
if(a>b)
    return a;
return b;
}

就可以了