2 Replies - 421 Views - Last Post: 25 June 2011 - 01:25 PM Rate Topic: -----

#1 sydie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • D.I.C Addict

Reputation: 231
  • View blog
  • 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  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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