简体   繁体   English

返回平均值、最大值、最小值的 Void 函数,并将数组和输入数量作为参数

[英]Void function that returns average,max,min,and takes as parameter an array and the number of inputs

So I'm trying to create a program that returns the average ,min and max from a void function.所以我正在尝试创建一个程序,该程序从 void 函数返回平均值、最小值和最大值。 I can't really see what is wrong with the code and I'm hoping someone can help.The compiler doesn't find any error or warning but when i run the program i get "Process exited with return value 3221225477".我真的看不出代码有什么问题,我希望有人能帮忙。编译器没有发现任何错误或警告,但是当我运行程序时,我得到“进程退出,返回值 3221225477”。 The problem seems to be in the function i created.问题似乎出在我创建的函数中。 Thanks in advance.提前致谢。

    void emporeuma(double array[], int plithos, double* avg, double* max, 
    double* min, int* plit)
    {
    int j;
    double sum;
    avg=0;
    sum=0;
   *plit=plithos;
    for(j=0;j<plithos-1;j++){

     sum=sum + array[j];
        }
    *avg=sum/plithos;
     *min=array[0];
     *max=array[0];
     for(j=1;j<plithos-1;j++)
     {
       if (array[j]>*max)
        {
          array[j]=*max;
           }

       if (array[j]<*min)
        {
        array[j]=*min;
         }

         }
    avg=0;
    ...
    *avg=sum/plithos;

crashes your program.使您的程序崩溃。 You probably want to write *avg = 0 .你可能想写*avg = 0

The loop is one too short, and the max and min tracking is back-to-front.循环太短了,最大和最小跟踪是从后到前的。 Here is a suggested edit of that part:这是该部分的建议编辑:

for(j = 1; j < plithos; j++) {    // extend to the last element
    if (array[j] > *max) {
        *max = array[j];          // update the max
    }
    if (array[j] < *min) {
        *min = array[j];          // update the min
    }
    sum += array[j];              // ready to calculate avg
}
avg = sum / plithos;              // average

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 减去最大值和最小值的平均值返回错误的结果 - Average subtracted of max and min returns wrong result 数组中的随机数,最大值,最小值,平均值 - Random numbers in array, max, min, average 编写一个 C function 称为组合,将 n 和 r 作为输入,并返回组合的数量 - Write a C function called combinations which takes n and r as inputs, and returns the number of combinations 使用函数查找数组的最大值,最小值和总和 - Find max, min and sum of an array using function C 中的平均值、最大值和最小值程序 - Average, max, and min program in C 是否可以编写一个 function 将 integer 数组作为参数并返回 C 中数组元素的数量 - is it possible to write a function that takes an integer array as argument and returns the number of elements of the array in C function 的输入和输出 void *function(){} - Inputs and outputs of the function void *function(){} 需要在阵列中找到最大,最小,平均数-未声明大小 - Need to find Max, Min, Avg number in Array - no size declared 查找未知数量的输入的平均值 - Find the average of an unknown number of inputs 编写一个 function 以 'a' 作为参数,如果 'a' 是上三角矩阵则返回 1,否则返回 0 - write a function that takes 'a'as a parameter and returns 1 if 'a' is upper triangular matrix , 0 otherwise
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM