Howdy!
I'm learning C and ran into the error above with the note:
"expected 'int *' but argument is of type 'int **' "
What exactly did I mess up and how do I fix it? Here is my full code:
#include <stdio.h>
void sum(int a[], int n, int *even_elt_sum_ptr, int *odd_elt_sum_ptr);
Code:
int main (void)
{
int n=10, *even_elt_sum_ptr , *odd_elt_sum_ptr , odd, even;
int a[10] = {1,2,3,4,5,6,7,8,9,10};
even_elt_sum_ptr = 0;
odd_elt_sum_ptr = 0;
sum(a, n, &even_elt_sum_ptr, &odd_elt_sum_ptr);
even = *even_elt_sum_ptr;
odd = *odd_elt_sum_ptr;
printf("the even sum is %d\n", even);
printf("the odd sum is %d\n", odd);
return 0;
}
void sum(int a[], int n, int *even_elt_sum_ptr, int *odd_elt_sum_ptr)
{
int x;
for (x=0;x<n;x++){
if (a[x] / 2 == 0){
*even_elt_sum_ptr = *even_elt_sum_ptr + a[x];
}
else
*odd_elt_sum_ptr = *odd_elt_sum_ptr + a[x];
}
}
The code is intended to take an array of 10 integers and return the sum of all of the odd elements and a separate sum for all of the even elements. As I am still learning I am open to any comments/suggestions on improvements that you see. Thanks in advance!