c - 我的c代码有什么问题

标签 c

我的 C 代码有问题。我想要编写的函数是一个数组,它接受 100 个数字并打印小于数组中数字平均值的素数。我遇到错误,但不知道为什么我的代码无法正常工作:

#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' 

最佳答案

主要问题是您在函数中重新声明了 arr

关于c - 我的c代码有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22729597/

相关文章:

c - 禁用 -dkms 错误

c - 如何在 ubuntu 中计算 C 程序的运行时间

C OpenSSLRSA双重加密失败

c - 信号终止处理程序和清理操作

c - 为什么要在方法定义文件中包含 header ?

c - 结束子进程而不返回值

c - 读入字符串的 fscanf 问题

c - C 中的函数模拟(用于测试)?

c - Matlab:帮助理解正弦曲线拟合

无法在 C 中使用 * void 指针初始化结构