Ejercicio de un parcial viejo

Usé el struct como el orto creo
 avatar
unknown
c_cpp
2 years ago
836 B
5
Indexable
#include <stdio.h>
#define N 5

struct paridad_t {
int n_pares;
int n_impares;
};

struct paridad_t contar_paridad(int a[], int tam){
    struct paridad_t result = {0,0};
    int i = 0;
    while (i<tam)
    {
        if (a[i] % 2 == 0)
        {
            paridad_t.n_pares = paridad_t.n_pares + a[i];  
        }
        else{
            paridad_t.n_impares = paridad.n_impares + a[i];
        }
        i++;
    }
    return struct paridad_t resultado;
    
};

void pedirarreglo(int n, int tam){
    int i = 0 ;
    while (i<tam)
    {
        printf("Coloca un valor para a[%d] = ",i);
        scanf("%d",&n[i]);
        i++;
    }
}

int main()
{
    int tam,a;
    tam = N;
    pedirarreglo(a,tam);
    printf("La cantidad de números pares es = %d y las impares es %d",paridad_t.n_pares,paridad_t.n_impares);
    return 0;
}
Editor is loading...