The bell number is the number of partitions of a set with n members.. look at the recursion formula in this link:

Bell number - Wikipedia, the free encyclopedia

so i have to do the recursive code in c++ , i've did without any troubles other recursive programs like the tower of hanoi, catalan numbers, fibonacci numbers, ackermann function, but the bell number not yet.

well this is the code that i had made, so ,i just wanna know if is my implementation correct? I'm assuming it's not, but where am I going wrong?

//bell number #include<iostream.h> #include<conio.h> long fact(int k) { if(k == 0) return 1; else return k * fact(k - 1); } long bell(int k, int n, int j) { if(k == 0) return 1; else return fact(n)/fact(j)* fact(n - j)) * bell * j; } int main () { int n, int j = 0, int sum = 0; cout << " BELL NUMBER " << endl; cout << " Enter the number of elements of the set /n"; cin >> n; for(j = 0; j < n; j++) { sum+ = j } cout << " the number of partitions of this set is " << bell(n)"/n"; getch(); return 0; }

Note: I don't know why, but it's not necessary put "using namespace std"

**Edited by Alexander, 18 October 2010 - 04:08 PM.**

Added [code] tags around code