如何选择特定数据? [英] How can I select a specific data?

查看:111
本文介绍了如何选择特定数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习处理,并且有一个分配问题告诉我使用while循环打印-100到100之间的随机数,然后打印出这些数字的平均值。我知道如何做第一部分而不是第二部分...



我尝试过的事情:



我不知道做任何替代方案我只是编程的初学者

I am learning processing and there is an assignment question that tells me to use while loop to print out random numbers between -100 and 100, then print out the average of those numbers. I know how to do the first part but not the second...

What I have tried:

I didn't know any alternatives to do it I'm just a beginner to programming

推荐答案

你可以创建一个循环,在它里面你有一个保存当前数字的变量。

你需要的是一个变量,它保存一个运行总计(在循环外声明它,并将其初始化为零),以添加当前数字每次围绕循环编号,以及你生成的数字的数量。

循环后,将总数除以计数,你得到平均值。



但这是你的功课,所以即使我知道你应该用什么语言,我仍然不会给你代码!试一试 - 它并不复杂。
You can create a loop, and inside it you have a variable which holds the current number.
All you need is a variable which holds a running total (declare it outside the loop, and initialize it to zero), to add the current number to it each time round the loop, and a count of how many numbers you generated.
After the loop, divide the total by the count and you have the average.

But it's your homework, so even if I had a clue what language you are supposed to use, I still wouldn't give you the code! Give it a try - it's not at all complicated.


这篇关于如何选择特定数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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