How would I calculate an average recursively in C? Let's say I have an array with 8 numbers. I will calculate the average of the first two, then third and fourth, ... Then I will do it again with the 4 numbers I have and repeat until I only have 2 numbers where I just add them and divide by two. But how do I implement this?
posted this on /g/, thought i'd also try the /g/ textboard as well. Please help!
>>1 How would I calculate an average recursively in C?
You wouldn't. C doesn't guarantee that tail calls will be eliminated, so every recursive function is a stack overflow waiting to happen.
See the second graph? You can compute the Fibonacci sequence directly with a bit of jiggling and an exp() function.
Name:
Anonymous2013-03-17 0:46
>>14
10 minutes in Racket. (define (integrate func m) (cond [(> m 0) (+ (func m) (sum func (- m (/ 0.1 1))))] [else 0]))
(define (factorial x)(* (integrate (lambda (t) (/ (expt t x) (expt 2.71828182846 t))) 100.00) (/ 1 10)))
Name:
Anonymous2013-03-17 0:47
This is a fun problem. Imagine you have an array, A = [x1, x2, ... xn], and you have calculated the average of the first n-1 terms, an-1. How do you calculate the average of all terms, using only n, xn, and an-1?
Name:
Anonymous2013-03-17 0:49
>>17 factorial
Shit! I meant fibs! Now I look stupid instead of playfully stupid. ;-,-)<==,|,^,|,==>(-,-;
>>2
he said recursively so his teacher probably forbade loops
anyway the task is retardedly simple >>8
lolwut, fibbonachi is easy to do with an ordinary while loop