This question already has answers here:
Closed 2 months ago.
What happens to a declared, uninitialized variable in C? Does it have a value?
(10个答案)
我在数组和指针上挣扎,我的函数给出了一个荒谬的数字。我找不到答案。
float computeAverage(float Array[],int Dim){
    int i;
    float media, soma;
    for(i = 0;i<Dim;i++)
        soma = soma + Array[i];
    media = soma/Dim;
    return (media);
}

最佳答案

 // you initialize your soma variable (soma = 0)
 float MA (float Array[], int Dim)
 {
     int i;
     float media, soma = 0;

     for (i = 0; i < Dim; i++)
         soma = soma + Array[i];
     media = soma / Dim;

     return media;
}

关于c - 计算数组的平均值,返回的值是无意义的。,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57731242/

10-11 21:19