Skip to content

Instantly share code, notes, and snippets.

@juanfal
Last active October 22, 2024 18:33
Show Gist options
  • Save juanfal/c46c981a00291141943c6d6650a3a2aa to your computer and use it in GitHub Desktop.
Save juanfal/c46c981a00291141943c6d6650a3a2aa to your computer and use it in GitHub Desktop.
exp x wo subprograms
// 01.exp.cpp
// juanfc 2013-10-11
// calcular el factorial directamente sumando N términos de su
// desarrollo en serie
// ver http://es.wikipedia.org/wiki/Serie_de_Taylor
#include <iostream>
using namespace std;
int main()
{
double exp(double x, int n=10);
for (double x = 1; x < 100; x+=10)
cout << "exp(" << x << ")= " << exp(x) << endl;
return 0;
}
double exp(double x, int n=10)
{
double fact = 1;
double pot = 1;
double s = 0;
for (int i = 1; i <= n; ++i) {
s += pot/fact;
pot *= x;
fact *= i;
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment