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.
jander1Asked:
Who is Participating?
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.

TommySzalapskiCommented:
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)
}
0
TommySzalapskiCommented:
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.
0
jander1Author Commented:
hi thanks for your responce!

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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

jander1Author Commented:
Hi TommySzalapski,

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

thanks.
0
jander1Author Commented:
will


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

work as the 9 times table?

thanks
0
TommySzalapskiCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Algorithms

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.