Once again, I dive into the murky waters of mathematics for this month’s Exercise. The challenge is to code the Series That Has No Name (STHNN), which converges on the value 5e.
From the original post, Figure 1 shows the series as it’s written in mathematical hieroglyphics. The task is to convert these cryptic symbols into C code, with the program spitting out the value of e, Euler’s number.

Figure 1. The frightening mathematical Series That Has No Name.
For my solution I use two functions: factorial() and cube().
The factorial() function I stole from an earlier Lesson, which I hinted at in the Exercise post. The cube() function returns the argument passed cubed. I could use the pow() function, but just decided instead to multiply the passed value thrice, as shown below.
2026_06-Exercise.c
#include <stdio.h> /* calculate the factorial */ long factorial(long f) { if( f==1 ) return(f); else return(f * factorial(f-1)); } /* calculate the cube */ long cube(long c) { return( c*c*c ); } int main() { int x; float e = 0.0; for( x=1; x<50; x++ ) e += (float)cube(x)/factorial(x); printf("%f\n",e/5.0); return 0; }
The main() function uses a for loop to calculate the value of variable e, which is initialized to zero when the variable is declared:
float e = 0.0;
In the for loop, variable e is increased each iteration by the value of x cubed divided by x factorial. It’s a simple expression that represents the STHNN. I set the upper limit on variable x to 50 as larger values overflow but 50 still results in an approximation of e that works.
Because the STHNN results in 5e, the result output is divided by 5.0, which results in e:
2.718282
I hope that your solution met with success.
I have a terrible affliction that causes me to over-think and over-engineer everything 🙂
In this case I put together a ridiculously complicated solution which splits out the cubes and factorials into separate arrays. The rationale is that populating them could be spread across different processes, and the cubes could be split into chunks in a sort of map/reduce thing. This might actually be a worthwhile pattern if you need to evaluate an infinite series to a very high value of n.
Maybe I’ll build a Raspberry Pi cluster to try it out but my occasional forays into electronics usually results in burnt fingers and solder splattered all over the place causing shorts which make components blow up.
#include<stdio.h>
#include<math.h>
void calc_cubes(double* cubes, int n);
void calc_facs(double* facs, int n);
double calc_e(double* cubes, double* facs, int n);
int main()
{
int n = 64;
double cubes[n] = {};
double facs[n] = {};
calc_cubes(cubes, n);
calc_facs(facs, n);
// for(int i = 1; i < n; i++)
// printf(“%d ^3 = %lf\n”, i, cubes[i]);
// for(int i = 1; i < n; i++)
// printf(“%d! = %lf\n”, i, facs[i]);
double e = calc_e(cubes, facs, n);
// printf(“math.h M_E undefined %lf”, M_E);
printf(“e undefined %lf”, e);
}
void calc_cubes(double* cubes, int n)
{
for(int i = 1; i < n; i++)
{
cubes[i] = i*i*i;
}
}
void calc_facs(double* facs, int n)
{
facs[1] = 1.0;
for(int i = 2; i < n; i++)
{
facs[i] = facs[i-1] * i;
}
}
double calc_e(double* cubes, double* facs, int n)
{
double sum = 0;
for(int i = 1; i < n; i++)
{
sum += cubes[i] / facs[i];
}
return sum / 5.0;
}
I messed up converting the code to HTML. The “undefined” should be the approximately equals sign ≈.
The output is:
e ≈ 2.718282
which is what I was hoping for.
btw I couldn’t get M_E to work which is why the line using it is commented out. I’m using gcc version 13.3.0. Any ideas?
I’ve solved the problem. You have to do this:
#define _DEFAULT_SOURCE
before this:
#include.
(It differs depending on implementation.) The commented line now prints:
math.h M_E ≈ 2.718282
I find the complexity delightful! I suffer from the same affliction, often storing data as opposed to just consuming it. Often times this approach proves valuable later.
Thank you for sharing!