I just did an assignment too quickly so I want to make sure that I did it right. It works properly but seems too easy to be true.
The assignment says to write a program that defines and uses macro SUMMARY to sum the values in a numeric array. The macro should recieve the array and the number of elements in the array as arguments.
I was not sure if I am supposed to somehow add the elements when I define it or as I did which works fine. Any advise is appreciated thanks.
Code:#include <stdio.h> #define SUMMARY (total) #define SIZE 10 int main() /* program main begins execution */ { int A[SIZE] ={1,2,3,4,5,6,7,8,9,10}; /* define array */ int i; /* counter */ int total = 0; /* initialize total to zero */ for (i=0; i< SIZE; i++ ) { /* compute total */ total += A[i]; } printf( "Total value of array is %d\n", SUMMARY ); /* print results */ return 0; /* indicates successful program execution */ }