一维数组的常见操作与应用
1. 计算总和与平均值
在一些应用场景中,我们需要计算数组元素的总和与平均值。以 Starward Coffee 应用为例,该应用旨在显示 12 个月内咖啡使用的总磅数以及每月的平均使用磅数。
问题描述 :
Starward Coffee 的商店经理需要一个应用程序,该程序能够显示两个信息:12 个月内咖啡使用的总磅数和每月的平均使用磅数。去年每月的使用量分别为:400.5、450、475.5、336.5、457、325、220.5、276、300、320.5、400.5 和 415。
代码实现 :
Private poundsUsed() As Double = {400.5, 450, 475.5,
336.5, 457, 325,
220.5, 276, 300,
320.5, 400.5, 415}
Private Sub forNextButton_Click(sender As Object,
e As EventArgs) Handles forNextButton.Click
' displays the total and average pounds used
Dim highSub As Integer = poundsUsed.GetUpperBound(0)
Dim total As Double
Dim average As Double
' accumulate pounds used
For subscript As I
超级会员免费看
订阅专栏 解锁全文
665

被折叠的 条评论
为什么被折叠?



