C++ 实例 - 判断三个数中的最大数
C++ 教程
· 2019-02-26 11:58:56
通过屏幕我们输入三个数字,并找出最大的数。
实例 - 使用 if
#include <iostream>
using namespace std;
int main()
{
float n1, n2, n3;
cout << "请输入三个数: ";
cin >> n1 >> n2 >> n3;
if(n1 >= n2 && n1 >= n3)
{
cout << "最大数为: " << n1;
}
if(n2 >= n1 && n2 >= n3)
{
cout << "最大数为: " << n2;
}
if(n3 >= n1 && n3 >= n2) {
cout << "最大数为: " << n3;
}
return 0;
}
以上程序执行输出结果为:
请输入三个数: 2.3 8.3 -4.2 最大数为: 8.3
实例 - 使用 if...else
#include <iostream>
using namespace std;
int main()
{
float n1, n2, n3;
cout << "请输入三个数: ";
cin >> n1 >> n2 >> n3;
if((n1 >= n2) && (n1 >= n3))
cout << "最大数为: " << n1;
else if ((n2 >= n1) && (n2 >= n3))
cout << "最大数为: " << n2;
else
cout << "最大数为: " << n3;
return 0;
}
以上程序执行输出结果为:
请输入三个数,以空格分隔: 2.3 8.3 -4.2 最大数为: 8.3
实例 - 使用内嵌的 if...else
#include <iostream>
using namespace std;
int main()
{
float n1, n2, n3;
cout << "请输入三个数: ";
cin >> n1 >> n2 >> n3;
if (n1 >= n2)
{
if (n1 >= n3)
cout << "最大数为: " << n1;
else
cout << "最大数为: " << n3;
}
else
{
if (n2 >= n3)
cout << "最大数为: " << n2;
else
cout << "最大数为: " << n3;
}
return 0;
}
以上程序执行输出结果为:
请输入三个数,以空格分隔: 2.3 8.3 -4.2 最大数为: 8.3
点击查看所有 C++ 教程 文章: https://codercto.com/courses/l/18.html
产品的视角:从热闹到门道
后显慧 / 机械工业出版社 / 2016-1-1 / 69.00
本书在创造性的提出互联网产品定义的基础上,为读者提供了一个从0基础到产品操盘手的产品思维培养方法! 全书以互联网产品定义为基础,提出了产品思维学习的RAC模型,通过认识产品、还原产品和创造产品三个阶段去培养产品思维和产品认知。 通过大量的图片和视觉引导的方法,作者像零基础的用户深入浅出的描绘了一条产品经理的自我修养路径,并且提供了知识地图(knowledge map)和阅读雷达等工具,......一起来看看 《产品的视角:从热闹到门道》 这本书的介绍吧!