Can a function call itself?
Hi all, I have to program a recursion to find the answer to a maths question, the recursion formula I am working with is:
f(a,b) = f(a,b-1) - f(a/g(b),b-1)
where g is an arbitary function that is easy to use
I also have the condition that f(a,0)=a
What is the best way to go about programming this kind of thing in C?
My initial idea was to have the function call itself if b wasn't 0, but that doesn't seem to work, will this method work or is there a much better SIMPLE way?
Correction to initial Code
Sorry just to give a quick example of some input, so i gave f(10,5)
Code:
MainCL{
printf("%d", f(10,5));
}
int f(int a, int b){
if(b==0){
return a;}
else{
return f(a,(b-1))-f(a/2,(b-1));}
}