1. ## recursive function

hi there.
i just started c programming 2 weeks ago and i have a project which is due in a weeks time.

there is a question which i am stuck at:

Write a recursive function TotalQuotients that take in 3 float parameters start, end anf factor. TotalQuotients sum up all quotients of start and factor. For each recursion, start is added by factor, up to or including end.
For example:
TotalQuotients(3.0, 7.0, 1.5) returns 9.0 ((3.0/1.5)+(3.0+1.5)/1.5+(4.5+1.5)/1.5)

Later change the above to an iterative solution.

Hope someone will be able to hel pme with this.

thank you.

I didn't understand the question in the beginning too!
But this is what my classmates explained to me, and they are also stucked on how to get the equation out.

Example:
TotalQuotients(3.0, 7.0, 1.5) returns 9.0
((3.0/1.5)+(3.0+1.5)/1.5+(4.5+1.5)/1.5)

Start = 3.0
End = 7.0
Factor = 1.5

therefore, "Start" add "Factor" until <= "End"(7.0),
later divide by "Factor".
it is like the "Start" increases by 1.5 until <= End.

and each sum must be divided by the factor (1.5). Or maybe they all can be added up first before dividing by 1.5 (as 1.5 is the common denominator).

Thanks again!

3. You just started programming two weeks ago- and you are allready doing recursion. WOW!! that is quick!!! This is something that is not very basic.

4. it is a 3 month module program...
it'skinda tuff when i have no programming background, but i guess i won't give up now.

i referred to a book Art of C Programming, but there was only one example on recursive functions, which is the calculation of factorials...

BTW, must there always be a "return" used in a recursive function?

5. Originally posted by hnc
BTW, must there always be a "return" used in a recursive function?
Technicly, no. For example, this is valid code. Compile it and watch what happens:
Code:
```void fun(void) {
int x[1024];
fun( );
}

int main (void)
{
fun( );
return 0;
}```
The program will eventually (fairly quickly) crash because it will run out of stack space. Stack space is basicly the amount of memory alloted to the program for storing variables and calling functions.

Since nothing ever tells the function to stop recursing, it calls itself indefinately, and runs out of stack space, causing your program to crash.

So the answer is "no", but in practice it's "yes".

Quzah.