设计一个函数随机产生六个整数计算六个整数的平均值

1个回答

  • VB:

    Private Sub Command1_Click()

    Randomize

    Dim Arr(1 To 6) As Integer

    For i = 1 To 6

    Arr(i) = Int(Rnd * 1000)

    Print Arr(i);

    Avg = Avg + Arr(i)

    Next i

    Print

    Print "平均值:" & Avg / 6

    End Sub

    C++:

    #include

    #include

    using namespace std;

    int main()

    {

    setlocale(0,"chs");

    srand(time(0));

    int a[5],i,sum=0;

    double avg;

    for(i=0;i