Even zeroed sum

Asked

Viewed 42 times

3

This function should add the pair, but it is not, I did not understand the pq.

#include <stdio.h>

int somapar(int vet[], int n) {
    int soma = 0, i;

    for (i = 0; i < n; i++) {
        if (vet[n] % 2 == 0) 
            soma = soma + vet[n];
    }
    return soma;
}


int main () {

    int v[20] = {2, 1, 8, 3, 4};
    int a;

    a = somapar (v, 5);
    printf ("%d ", a);

    return 0;
}

1 answer

3


Code:

#include <stdio.h>

int somapar(int vet[], int n) {
    int soma = 0, i;

    for (i = 0; i < n; i++) {
        if (vet[i] % 2 == 0)
            soma = soma + vet[i];
    }
    return soma;
}


int main() {

    int v[20] = {
        2, 1, 8, 3, 4
    };
    int a;

    a = somapar(v, 5);
    printf("%d ", a);

    return 0;
}

Check the vet[i]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.