📅  最后修改于: 2020-09-25 06:11:35             🧑  作者: Mango
在此程序中,要求用户输入三个数字。
然后,该程序在用户输入的三个数字中找出最大的数字,并显示适当的消息。
该程序可以以多种方式使用。
#include
using namespace std;
int main() {
float n1, n2, n3;
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;
if(n1 >= n2 && n1 >= n3)
cout << "Largest number: " << n1;
if(n2 >= n1 && n2 >= n3)
cout << "Largest number: " << n2;
if(n3 >= n1 && n3 >= n2)
cout << "Largest number: " << n3;
return 0;
}
输出
Enter three numbers: 2.3
8.3
-4.2
Largest number: 8.3
#include
using namespace std;
int main() {
float n1, n2, n3;
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;
if((n1 >= n2) && (n1 >= n3))
cout << "Largest number: " << n1;
else if ((n2 >= n1) && (n2 >= n3))
cout << "Largest number: " << n2;
else
cout << "Largest number: " << n3;
return 0;
}
输出
Enter three numbers: 2.3
8.3
-4.2
Largest number: 8.3
#include
using namespace std;
int main() {
float n1, n2, n3;
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;
if (n1 >= n2) {
if (n1 >= n3)
cout << "Largest number: " << n1;
else
cout << "Largest number: " << n3;
}
else {
if (n2 >= n3)
cout << "Largest number: " << n2;
else
cout << "Largest number: " << n3;
}
return 0;
}
输出
Enter three numbers: 2.3
8.3
-4.2
Largest number: 8.3