我的C代码有问题。我想写的函数是一个数组,其中包含100个数字,并打印出小于数组中数字平均值的素数。我有一个错误,我不知道为什么我的代码不工作:我的代码在c中出现了什么问题
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define SIZE 100
void Array123(int arr[]) {
int i = 0, arr[SIZE], j, count = 0;
float sum = 0, avg;
do{
scanf(" %d", &arr[i]);
i++;
count++;
sum += arr[i];
}
while ((arr[i] != 0) || (i < SIZE));
avg = sum/count;
for (j = 2; j <= arr[i] - 1; j++) {
if (arr[i] % j == 0) {
break;
}
}
if (j == arr[i]) {
if (arr[i] < avg) {
printf("%d", arr[i]);
}
}
}
int main() {
int arr[SIZE], i, x;
for (i = 0; i < SIZE; i++) {
x = Array123(arr[SIZE]);
printf(" %d", x);
}
}
注意,我被允许使用数组指针没有。
的错误是:
Warning 2 warning C4047: 'function' : 'int *' differs in levels of indirection from 'int'
Warning 3 warning C4024: 'Array123' : different types for formal and actual parameter 1
5 IntelliSense: argument of type "int" is incompatible with parameter of type "int *" 41 14
Error 4 error C2120: 'void' illegal with all types 41 1
Error 1 error C2082: redefinition of formal parameter 'arr'
您应该格式化您的代码,以便它对我们和您来说更具可读性。 –