# Write, using a functional programming approach, a function to calculate recursively (using the + operation) any entry in the nine times table.

Write, using a functional programming approach, a function to calculate recursively (using the
+ operation) any entry in the nine times table.
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
This looks like a homework question so we cannot give direct answers. Where are you stuck? Recursion is basically just writing a fuction that does a small part of the problem and then calls itself to complete the problem.
The other important part is the stop condition (so the function knows when to stop calling itself). Here is a simple example

int factorial(int n)
{
if( n == 0)
return 1;
else
return n*factorial(n-1)
}
Commented:
You are being asked to write a similar function for the 9 row in the multiplication table so if the function is passed any number, it returns 9 times that number using a function like the one above.

Let me know if you need any more help.
Author Commented:

it's not a homework question its just the way i worded it basicly i need a fuctional Recursion for the 9 times table? if you think its homework then can u give me one for like the 8 or 10 times table?

thanks.
Author Commented:
Hi TommySzalapski,

Thank for your reply. can you confirm what the exact function is? this isn't homework

thanks.
Author Commented:
will

int factorial(int n)
{
if( n == 0)
return 1;
else
return n*factorial(n-1)
}

work as the 9 times table?

thanks
Commented:
Okay. I believe you that this isn't homework. So I'll give you the 9s row. If you are trying to learn, you do learn better the more you do yourself, so try to make some other recursive functions too.

int timesNine(int n)
{
if(n == 0)
return 0;
else
return 9 + timesNine(n-1);
}

See how that works? It adds 9 every time and then subtracts 1 from n. So if you do timesNine(8) it gives you 9 + timesNine(7) which equals 9 + 9 + timesNine(6) etc.

Experts Exchange Solution brought to you by