This python code works properly and produces proper output:
def fib(x):
v = 1
u = 0
for x in xrange(1,x+1):
t = u + v
u = v
v = t
return v
But when I write the same code in C++ it gives me a different and impossible result.
int fib(int x)
{
int v = 1;
int u = 0;
int t;
for (int i = 1; i != x + 1; i++)
{
t = u + v;
u = v;
v = t;
}
return v;
}
I'm still learning c++. Thanks!
Edit: C++ outputs -1408458269.
Python outputs 20365011074 when x = 50.