I have a sequence.
a1 = 1 - cos(x);
ai = a1 + (-1)^(i-1) * x^(2*i-2) / (2*i-2)!
I need to write this with and without recursion. But it has a different results.
Here is my code: http://codepaste.net/q213q6
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m going to operate under the assumption that this is homework, if I’m wrong I’ll come back and edit this post or repost.
Firstly, you should try to write your factorial function in a tail recursive manner. Though it probably won’t make much difference in C, it’s good practice.
Next, you don’t generally want to put a loop inside of your recursive functions, that somewhat defeats the point. Think of a recursive call as one iteration with a test and either return or recall.