Friday, October 6, 2023

Sum of Infinite Series

#include <iostream>
#include <cmath>
using namespace std;

double p10 (int N)
{
   double s = 1, pm = -1, k = 1;
   for (int i = 1; i <= N; i++)
   {
   k = k * i;
   s = s + pm / k;
   pm *= -1;
   }
return (s);
}

int main ()
{
int n;
cout << "N=";
cin >> n;
cout << " s=" << p10 (n) << "\n1./e=" << 1. / exp (1.) << endl;
}

No comments:

Post a Comment

NaCl.xyz Generator with Interactive 3D Visualization

NaCl.xyz Generator with Interactive 3D Visualization NaCl.xyz Generator with Interactive 3D Visualization ...