# Calculate the average of non-sequential array

Page 1 of 1

## 2 Replies - 610 Views - Last Post: 25 June 2011 - 01:25 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=237011&amp;s=94eb27df0cbdf925b90f1d2638e81146&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 sydie

• New D.I.C Head

Reputation: 0
• Posts: 2
• Joined: 25-June 11

# Calculate the average of non-sequential array

Posted 25 June 2011 - 01:12 PM

Hello

below is the sample of the command i get from another thread.

```	int sum = 0;
int average = 0;
int array[10] = {1,2,3,4,5,6,7,8,9,10};
for (int i = 0; i < 10; ++i)
sum+=array[i];
average = sum/10;
count<<"Average:"<<average;

```

my question is how should i use "for" to calculate the average if the array is not in sequence ?

int numbers[6] = {215,418,152,415,475,612}

Thanks

Is This A Good Question/Topic? 0

## Replies To: Calculate the average of non-sequential array

### #2 sk1v3r

Reputation: 231
• Posts: 668
• Joined: 06-December 10

## Re: Calculate the average of non-sequential array

Posted 25 June 2011 - 01:18 PM

From what you have said, it seems that you have lifted the code from another post and do understand quite what is happening.
THey do not need to be in order.
If you step us through what you think is happening it will be easier to tell you what you want, but at the moment all I can say is that order has nothing to do with arrays.
Maybe these links will help:
http://www.cplusplus...torial/control/arrays
control structures (like for loops)

This post has been edited by sk1v3r: 25 June 2011 - 01:19 PM

### #3 sydie

• New D.I.C Head

Reputation: 0
• Posts: 2
• Joined: 25-June 11

## Re: Calculate the average of non-sequential array

Posted 25 June 2011 - 01:25 PM

thanks for the advise.i think i got the answer from the link your provided.thank you so much
http://www.cplusplus...utorial/arrays/