0

アルゴリズムに問題があります。必要なのは、再帰を介して配列の要素を乗算することです。これが私がこれまでに得たものです:

 #include <stdio.h>
    void vector(int vec[],int tam) {
    // gets a simple array
        int i;
        for (i=0; i<tam; i++) {
            printf("Ingrese un numero: ");
            scanf("%d",&vec[i]);
        }
    }
    int mv(int vec[], int tam, int pos) {
     // need help with the base and general case!
        if (tam==0) {
            return 1;
        } else {
            return vec[pos]*mv(vec,tam,pos+1);
        }   
    }

    int main() {
        int vec[3];
        vector(vec,3);
        printf("%d",mv(vec,3,0));
    }
4

1 に答える 1

0

ベースケースはif (pos == tam) return 1;

また、配列が空でないことを確認する必要があります

于 2012-08-31T04:37:34.563 に答える