Calculates the pentagonal number of the given order.

View versions (1)

Interface

#include <codecogs/maths/combinatorics/sequences/pentagonal_number.h>

using namespace Maths::Combinatorics::Sequences;

This function computes the pentagonal number of order n. The pentagonal number P(n) counts the number of dots in a figure of n nested pentagons. The pentagonal numbers are defined for both positive and negative orders.

Parameters

n
the desired order

Returns

the value of the pentagonal number of order n

Example:

#include <codecogs/maths/combinatorics/sequences/pentagonal_number.h>
#include <iostream>
int main()
{
  std::cout << "Pentagonal numbers for 0 <= n < 10" << std::endl;
  for (int i = 0; i < 10; i++)
    std::cout << i << "  " << Maths::Combinatorics::Sequences::pentagonal_number(i) << std::endl;
  return 0;
}

Output:

Pentagonal numbers for 0 <= n < 10
0  0
1  1
2  5
3  12
4  22
5  35
6  51
7  70
8  92
9  117

References

SUBSET, a C++ library of combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html

GPL Licence — free for non commercial use. See Licence details.

Interactive Calculator

n
Result