Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

TermxRecursion.cpp

DZone's Guide to

TermxRecursion.cpp

·
Free Resource
#include 
 
  

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();
}

 
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}