simple recursive program

Wrote this simple recursive program... didn't worked... checked the book, it's written just like there.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

using namespace std;

long fact(int n)
{
    if(n=0)
    return 1;
    else
    return n*fact(n-1);
}



main ()
{int number;
    cin>>number;
    cout<<fact(number);
}


this is what I get:

10

Process returned -1073741819 (0xC0000005) execution time : 1.182 s
Press any key to continue.
I presume you're trying to find the factorial? Try if(n<=1)
That = should be ==.
Oh wow haha. I'm not sure how I didn't catch that. I guess this is why we have many people answers questions
Topic archived. No new replies allowed.