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

N-point Star in Microsoft Visual Studio Console App

#include <windows.h> #include <cmath> #include <iostream> LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,...