# Entringer Number in C++

C++Server Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

66 Lectures 5.5 hours

Entringer Number is a special number which is equal to the number of permutations of {1, 2, 3, … n+1}, starting with K+1 which is updated by decreasing then increasing the values alternatively.

The value of Entringer Number is formulated using,

The recurrence relation,

E(n, k) = E(n, k-1) + E(n-1, n-k)

The base value is,

E(0,0) = 1

E(n, 0) = 0

We can find the Entringer number using,

N = 5, k = 3

E(5, 3) = 14

## Example

Live Demo

#include <iostream>
using namespace std;

int EntringerNumber(int n, int k)
{

if (n == 0 && k == 0)
return 1;
if (k == 0)
return 0;
return EntringerNumber(n, k - 1) + EntringerNumber(n - 1, n - k);
}

int main() {

int n = 5, k = 3;
cout<<"The value of E("<<n<<", "<<k<<") = "<<EntringerNumber(n, k);
return 0;
}

## Output −

The value of E(5, 3) = 14