How to resolve the algorithm Stirling numbers of the second kind step by step in the FreeBASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Stirling numbers of the second kind step by step in the FreeBASIC programming language
Table of Contents
Problem Statement
Stirling numbers of the second kind, or Stirling partition numbers, are the number of ways to partition a set of n objects into k non-empty subsets. They are closely related to Bell numbers, and may be derived from them.
Stirling numbers of the second kind obey the recurrence relation:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Stirling numbers of the second kind step by step in the FreeBASIC programming language
Source code in the freebasic programming language
dim as integer S2(0 to 12, 0 to 12) 'initially set with zeroes
dim as ubyte n, k
dim as string outstr
function padto( i as ubyte, j as integer ) as string
return wspace(i-len(str(j)))+str(j)
end function
for k = 0 to 12 'calculate table
S2(k,k)=1
next k
for n = 1 to 11
for k = 1 to 12
S2(n+1,k) = k*S2(n,k) + S2(n,k-1)
next k
next n
print "Stirling numbers of the second kind"
print
outstr = " k"
for k=0 to 12
outstr += padto(12, k)
next k
print outstr
print " n"
for n = 0 to 12
outstr = padto(2, n)+" "
for k = 0 to 12
outstr += padto(12, S2(n, k))
next k
print outstr
next n
You may also check:How to resolve the algorithm Draw a clock step by step in the Run BASIC programming language
You may also check:How to resolve the algorithm First-class functions/Use numbers analogously step by step in the Erlang programming language
You may also check:How to resolve the algorithm Classes step by step in the F# programming language
You may also check:How to resolve the algorithm Recaman's sequence step by step in the Fōrmulæ programming language
You may also check:How to resolve the algorithm Pascal's triangle/Puzzle step by step in the Wren programming language