| mitocondrio (7) | |
|
Hello, I'm doing a fatorial function like this: unsigned long long fatorial(int a) { xi = 1; rod = 0; for (f=0; f<a; f++) { xi *= rod + 1; rod++; } return (xi); } At the beggining fot like fatorial(5) it's ok, the function gives me 120, and for other numbers, but for like fatorial(17) it gives a crazy number that isn't the 17 fatorial. And if I do it without 'unsigned', it gives me a NEGATIVE number. WTF?? I even tried this: cout << 1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17; and it gives the number: -288522240 :( | |
|
|
|
| vlad from moscow (3650) | |
| xi shall be defined as unsigned long long. | |
|
|
|
| dumb0t (21) | |||
a little googling here and there should do the trick, if u really know how would u look for it
| |||
|
|
|||
| ne555 (4382) | |
|
@OP: overflow @dumb0t: imprecise By the way, `rod' and `f' have the same values; there is no need for both. | |
|
Last edited on
|
|