找到最小值 [英] Find the minimum value

查看:94
本文介绍了找到最小值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组数字(6,78,64,-1,6,-1),(那些不在数组中,并且这些值来自循环读数)。从这些数字,我想要一个方法找到最小值[最小值不应该是负值(-1)]。



像这样,

67,8,9,2,34,-1,5 -------; minimum = 2

如果所有值都是(-1)则-1,-1,-1,-1,-1,-1 ------;最小= -1





请有人建议方法吗?在此先感谢。!

解决方案

不,一个大的NO。没有人会从这里为你找到任何东西。这是你的功课,你应该这样做。

你不会学到任何东西,如果你希望别人为你工作的话。



你可以先自己尝试一下,当你卡在任何地方时,来自这里的任何人都会竭尽全力帮助你。但不要直接询问源代码



阅读代码项目快速解答常见问题解答 [ ^ ]首先:)



-KR


你会如何手动完成?



如果有人给你读了一组数字,你可能会在纸上逐一写下来。

你想要的最小数字将从一个非常大的数字开始并写入侧面,保存的最小值。

对于每个新的数字,如果它小于保存的最小值,你会比较它是否划过旧的最小值重视并用新的替换它。

除非它是-1,否则你只需忽略它并继续。



那是关于它的

I have a set of numbers (6,78,64,-1,6,-1), (those are not in array and that values get from a loop reading).From that numbers, I want to a method to find the minimum value [that minimum shouldn't be negative value(-1)].

Like this,
67,8,9,2,34,-1,5 -------; minimum = 2
if all values are (-1) then -1,-1,-1,-1,-1,-1------ ; minimum =-1


please anyone suggest a method? Thanks in advance.!

解决方案

No, a big NO. No one's from here going to find anything for you. It's your homework, you should do it.
"You won't be learn anything, if you expect others do your work for you".

You can try something on your own at first and when you stuck anywhere, anyone from here would do his/her best to help you out. But don't directly ask for the source code.

Read the Code Project Quick Answers FAQ[^] first :)

-KR


How would you do it manually?

If someone reads you a set of numbers you would probably write them down one by one on a paper.
For the minimum number you would start with a very big number and write to the side, the saved min value.
For every new number you compare if it is smaller than the saved min value and if it is you scratch the old min value out and replace it with the new.
Unless it is -1, then you just ignore it and continue.

That's about it.


这篇关于找到最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆