Ok still having trouble.
Here is the function that sums up the values of an array.
Code:
int sum_array(int a[], int num_elements)
{
int i, sum=0;
for (i=0; i<num_elements; i++)
{
sum = sum + a[i];
}
return(sum);
}
Now how to do the same exact thing using a macro? Here is what I tried. Its most likely complete nonsense.
Code:
#include <stdio.h>
# define SUMARRAY( int a[], int elements) ( some calculation involving int elements and int a[] )
int main( void )
{
int a[10] = {1, 2, 8, 2, 4, 5, 6, 9, 10, 19};
int sum;
}
Please help me out. The book doesn't explain this well, and I have no live instructor.
The second part of the macro should probably have something to do with the int elements, and sum them up somehow. But how?