#include <iostream>
using namespace std;
int main()
{
int num1,num2,num3,num4;
int x;
int y;
cin>>num1>>num2>>num3>>num4;
if (num1 > num2)
{
x=num1;
}
else
{x = num2;
}
if(num3>num4)
{y = num3;
}
else
{
y= num4;
}
if (x>y)
{cout<<"the largest number is:"<<x;
}
else
{
cout<<"the largest number is :"<<y;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是我打印4个数字中最大数字的代码.问题是我被要求优化或压缩解决方案.我试过但找不到另一种方法来编写这样的程序.任何人都可以帮我优化解决方案并使其更好..忽略语法错误..