Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sorry if this forum is not relevant for programming question, but please if possible help me. I have the following code to calculate the Bell number:

#include <iostream>
using namespace std;
int bell(int n,int m){
    if (n==1 && m==1)  return 1;
if (n >1 & m==1)  return  bell(n-1,n-1);
if (n>1  && (1< m && m<=n) ) 
 return  bell(n-1,m-1)+bell(n,m-1);

int main(){

return 0;

It shows me the following error

Line 9: warning: control reaches end of non-void function

Please help. Thanks a lot.

share|cite|improve this question

closed as off topic by Yuval Filmus, t.b., Gerry Myerson, Zev Chonoles Dec 13 '11 at 3:58

Questions on Mathematics Stack Exchange are expected to relate to math within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Where did you get this? – J. M. Sep 3 '11 at 12:05
up vote 1 down vote accepted

The reason why that error occurs is because you do not have an else statement with a return in it, it is a standard compiler warning.

As your compiler does not know what the values of m and n are going to be at compile time, it does not know whether one of the if tests will succeed and cause a return. Therefore, it thinks that it is possible that it can happen that your function just simply does not return anything in some cases.

share|cite|improve this answer

Consider what happens if $n \leq 0$ or $m \leq 0$.

share|cite|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.