如何从用户的5个输入中找到最大值? [英] How to find Maximum value from 5 inputs by user?
本文介绍了如何从用户的5个输入中找到最大值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果用户输入了五个值,如何找到这五个值之间的最大值?
If a user inputs five values, how to find a maximum value between those 5?
cin >> a >> b >> c >> d >> e;
在此代码中,我们进行了5次输入.现在,我们必须找到用户输入的最大值.
In this code we took 5 inputs. Now we have to find maximum value entered by the user.
推荐答案
您可以尝试此答案
for (i = 0; i < 5; i++) {
cin>>a[i];
}
//Assume that a[0] is greatest value
greatest = a[0];
for (i = 0; i < 10; i++) {
if (a[i] > greatest) {
greatest = a[i];
}
}
printf("Greatest of ten numbers is %d", greatest);
return 0;
这篇关于如何从用户的5个输入中找到最大值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文