#### c - output is not changing after being put through a function

``````#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int functionSumAvg(int sumAvgInput);

void main()
{
int amountOfNumbers,number,x,output;

output = 0;

printf("Enter how many numbers you want: ");
scanf("%d",&amountOfNumbers);
printf("Input each number, separated by a space: ");

for(x = 0; x < amountOfNumbers; ++x){
scanf("%d",&number);
int output = functionSumAvg(number);

}
printf("output: %d",output);
}

int functionSumAvg(int sumAvgInput){
int sum =+ sumAvgInput;
return sum;
}
``````

3 个回复
``````   int output = functionSumAvg(number);
``````

`````` output = functionSumAvg(number);
``````

``````int functionSumAvg(int *sum_pt, int input){…}
``````

`fuctionSumAvg`不计算任何东西的总和或平均值。 它只是将局部变量`sum`设置为其接收的数字，并返回该数字。 它没有将其添加到以前的总计中。 计算平均值需要将总和除以元素数，但是您绝不能对任何总和进行计数。

``````int functionSumAvg(int sumAvgInput, int *avg){ // return value is sum
static int sum = 0;
static int count = 0;
sum += sumAvgInput;
count++;
*avg = sum/count;
return sum;
}
``````

``````int sum, average;
sum = functionSumAvg(number, &average);
printf("Sum = %d Average = %d\n", sum, average);
``````
1 数组通过void函数后未更改

2 C＃-为什么在通过方法放置此变量后不更改[重复]

3 通过C中的函数更改字符串

2014-10-19 02:54:09 1 38   c/ string
4 struct中的字符串放入vector后无法输出---问题

2020-10-21 03:28:39 1 51   c++
8 通过函数操作数组的输出中的 C 错误

2020-04-25 16:14:20 1 28   c/ dynamic
9 传递给函数后，在Javascript中更改Labels值

2013-08-26 02:17:09 2 105   label