How to resolve the algorithm Calculating the value of e step by step in the Processing programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Calculating the value of e step by step in the Processing programming language

Table of Contents

Problem Statement

Calculate the value of   e.

(e   is also known as   Euler's number   and   Napier's constant.)

See details: Calculating the value of e

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Calculating the value of e step by step in the Processing programming language

Source code in the processing programming language

void setup() {
  double e = 0;
  long factorial = 1;
  int iterations = 11;
  for (int i = 0; i < iterations; i++) {
    e += (double) (2 * i + 1) / factorial;
    factorial *= (2 * i + 1) * (2 * i + 2);
  }
  println("After " + iterations + " iterations");
  println("Computed value: " + e);
  println("Real value: " + Math.E);
  println("Error: " + (e - Math.E));
  
  iterations = 21;
  for (int i = 11; i < iterations; i++) {
    e += (double) (2 * i + 1) / factorial;
    factorial *= (2 * i + 1) * (2 * i + 2);
  }
  println("After " + iterations + " iterations");
  println("Computed value: " + e);
  println("Real value: " + Math.E);
  println("Error: " + (e - Math.E));
}


  

You may also check:How to resolve the algorithm Hilbert curve step by step in the Processing programming language
You may also check:How to resolve the algorithm Empty program step by step in the Processing programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the Processing programming language
You may also check:How to resolve the algorithm Rename a file step by step in the Processing programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the Processing programming language