# Calculate the average of non-sequential array

Page 1 of 1

## 2 Replies - 855 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=f78ddf376c563789cea1904b5a4286ba&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

• D.I.C Addict

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

Was This Post Helpful? 1

### #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/
Was This Post Helpful? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }