Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate


Wednesday, May 9th, 2007 at 10:15:42pm UTC 

  1. int *curr_val;
  2. int history[5];
  4. curr_val = history; // point to the first element of history
  6. // to get a new element:
  7. *curr_val++ = get_new_value();
  8. // make sure to wrap at the end of the history array
  9. // alternatively, replace the pointer with an index value and access the array through that
  10. if(curr_val > &history + 5) curr_val = history;
  12. // for getting the average sum up all values in the array history
  13. int avg;
  14. avg = 0;
  15. for(int i = 0; i < 5; i++) avg += history[i];
  16. avg /= 5;
  18. // now avg has the average of the last 5 elements, including the value we gathered at the start of this snippet
  22. get_new_value = whatever I want to add, such as data or w/e right? followed by a ()


Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)

Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus