n-th element of the fibonacci sequence.
What are the bugs in below code and how to fix?.
Code:int fib(int n) {
int tmp;
if (n == 0) return 0;
if (n == 1) return 1;
tmp = fib(n-2);
tmp += fib(n-1);
return tmp;
}
Printable View
n-th element of the fibonacci sequence.
What are the bugs in below code and how to fix?.
Code:int fib(int n) {
int tmp;
if (n == 0) return 0;
if (n == 1) return 1;
tmp = fib(n-2);
tmp += fib(n-1);
return tmp;
}
What makes you think there are bugs in the first place?
That said, what happens if n is negative?
Thanks...Please help me debug this code..
what compiler i need to use?.
i put this code in miracle C compiler...gives me bug.
Whether there is a bug or not depends on the specification. As it stands, it is correct, except that negative input would cause an error. Other possible issues include the fact that it is inefficient.Quote:
No bug in this code?
I have heard that Miracle C is miraculously disastrous, so perhaps it would better if you switched compiler.Quote:
i put this code in miracle C compiler...gives me bug.
The GNU C compiler is available at zero price (use MinGW port for Windows), as is Microsoft Visual C++ 2008 Express (which comes with a C compiler).Quote:
what compiler i need to use?.
Microsoft Visual Studio Express Edition is bulky compiler. i installed...this tool got a learning curve.
i want a light weight, less resource, free C compiler to learn C...
i am not going code C...just want to brush up my C skills.
The MinGW port of GCC that I listed would be appropriate.Quote:
i want a light weight, less resource, free C compiler to learn C...
what version i need to download?
http://gcc.gnu.org/
For Windows, it would be here: MinGW. Use the installer package.
downloaded and installed.
how to start this tool and debug code?
You run it from the command prompt:Quote:
how to start this tool and debug code?
then run program.exeCode:gcc -o program.exe sourcefile.c
But yes, for more information, refer to the GCC website.
if n is negative code won't work.
Need to add check to see, n is positive beore passing n to this code.
what else i need to modify this code to work?