# Define and use a macro sumarray to sum the values of a numeric array.

Page 1 of 1

## 2 Replies - 1268 Views - Last Post: 11 July 2011 - 03:04 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=239044&amp;s=9abe310d0a439c496f197736fd37f947&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 wickedwhitetails

Reputation: 0
• Posts: 4
• Joined: 23-June 11

# Define and use a macro sumarray to sum the values of a numeric array.

Posted 11 July 2011 - 02:42 PM

Ok well I have been working on this assignment and I think that I am very close but it just doesnt seem to finish. It compiles and flashes up the little black window after compiling but it doesnt keep it open so I dont know if it is doing what it need to do or not. If anyone could help me to get to the window to stay open so that I can see if this is working that would be great.

```#include <stdio.h>
#define SUMARRAY(arr) \
sum = 0; \
for(int i = 0; i < (sizeof(arr) / sizeof(arr[0])); i++) \
{ \
sum += arr[i]; \
}
int main(void)
{
int sum;
int arr1[] = {1, 2};
int arr2[] = {1, 2, 3};
int arr3[] = {1, 2, 3, 4};
int arr4[] = {1, 2, 3, 4, 5};
int arr5[] = {1, 2, 3, 4, 5, 6};
SUMARRAY(arr1);
printf("Sum of the values in arr1 is: %d\n", sum);
SUMARRAY(arr2);
printf("Sum of the values in arr2 is: %d\n", sum);
SUMARRAY(arr3);
printf("Sum of the values in arr3 is: %d\n", sum);
SUMARRAY(arr4);
printf("Sum of the values in arr4 is: %d\n", sum);
SUMARRAY(arr5);
printf("Sum of the values in arr5 is: %d\n", sum);
return 0;
}

```

Is This A Good Question/Topic? 0

## Replies To: Define and use a macro sumarray to sum the values of a numeric array.

### #2 #define

• Duke of Err

Reputation: 1743
• Posts: 6,200
• Joined: 19-February 09

## Re: Define and use a macro sumarray to sum the values of a numeric array.

Posted 11 July 2011 - 03:02 PM

You can hold the console window open, by reading a character at the end of the program.

```  getchar();

return 0;
}

```

### #3 jjl

• Engineer

Reputation: 1169
• Posts: 4,785
• Joined: 09-June 09

## Re: Define and use a macro sumarray to sum the values of a numeric array.

Posted 11 July 2011 - 03:04 PM

You need to pause your program's execution before return 0;. I believe you can use getchar() before return 0 to pause the program execution for character input ; however, you may need to flush the input buffer first.

Edit: ninja'd

This post has been edited by ImaSexy: 11 July 2011 - 03:06 PM