Bell numbers: Difference between revisions

Line 123:
4140, 5017, 6097, 7432, 9089, 11155, 13744, 17007, 21147
21147, 25287, 30304, 36401, 43833, 52922, 64077, 77821, 94828, 115975</pre>
 
=={{header|C#|C_sharp}}==
{{trans|D}}
<lang cs>using System;
using System.Numerics;
 
namespace BellNumbers {
public static class Utility {
public static void Init<T>(this T[] array, T value) {
if (null == array) return;
for (int i = 0; i < array.Length; ++i) {
array[i] = value;
}
}
}
 
class Program {
static BigInteger[][] BellTriangle(int n) {
BigInteger[][] tri = new BigInteger[n][];
for (int i = 0; i < n; ++i) {
tri[i] = new BigInteger[i];
tri[i].Init(BigInteger.Zero);
}
tri[1][0] = 1;
for (int i = 2; i < n; ++i) {
tri[i][0] = tri[i - 1][i - 2];
for (int j = 1; j < i; ++j) {
tri[i][j] = tri[i][j - 1] + tri[i - 1][j - 1];
}
}
return tri;
}
 
static void Main(string[] args) {
var bt = BellTriangle(51);
Console.WriteLine("First fifteen and fiftieth Bell numbers:");
for (int i = 1; i < 16; ++i) {
Console.WriteLine("{0,2}: {1}", i, bt[i][0]);
}
Console.WriteLine("50: {0}", bt[50][0]);
Console.WriteLine();
Console.WriteLine("The first ten rows of Bell's triangle:");
for (int i = 1; i < 11; ++i) {
//Console.WriteLine(bt[i]);
var it = bt[i].GetEnumerator();
Console.Write("[");
if (it.MoveNext()) {
Console.Write(it.Current);
}
while (it.MoveNext()) {
Console.Write(", ");
Console.Write(it.Current);
}
Console.WriteLine("]");
}
}
}
}</lang>
{{out}}
<pre>First fifteen and fiftieth Bell numbers:
1: 1
2: 1
3: 2
4: 5
5: 15
6: 52
7: 203
8: 877
9: 4140
10: 21147
11: 115975
12: 678570
13: 4213597
14: 27644437
15: 190899322
50: 10726137154573358400342215518590002633917247281
 
The first ten rows of Bell's triangle:
[1]
[1, 2]
[2, 3, 5]
[5, 7, 10, 15]
[15, 20, 27, 37, 52]
[52, 67, 87, 114, 151, 203]
[203, 255, 322, 409, 523, 674, 877]
[877, 1080, 1335, 1657, 2066, 2589, 3263, 4140]
[4140, 5017, 6097, 7432, 9089, 11155, 13744, 17007, 21147]
[21147, 25287, 30304, 36401, 43833, 52922, 64077, 77821, 94828, 115975]</pre>
 
=={{header|D}}==
1,452

edits