Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

termxRecursion.cpp (See related posts)

#include <iostream>

using namespace std;

float term(float x, int n)
{
if (n==0)
return 1;
else
return -x*term(x,n-1);
}

float logr(float x, int n)
{
if (n==3)
return 0;
else
return term(x,n)/(float)n + logr(x, n+1);
}

float log(float x)
{
return logr(x-1,1);
}

main()
{
cout << term(1,1) << " " << term(3,1) << endl;
cout << log(1.0) << " " << log(2.71828) << endl;
getchar();
}

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts