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; }
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?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Thanks...Please help me debug this code..
what compiler i need to use?.
i put this code in miracle C compiler...gives me bug.
Last edited by me001; 09-23-2008 at 09:58 AM.
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.No bug in this code?
I have heard that Miracle C is miraculously disastrous, so perhaps it would better if you switched compiler.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).what compiler i need to use?.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
"No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
"Have you tried turning it off and on again?" - The IT Crowd
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.
Last edited by me001; 09-23-2008 at 09:33 AM.
The MinGW port of GCC that I listed would be appropriate.i want a light weight, less resource, free C compiler to learn C...
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
what version i need to download?
http://gcc.gnu.org/
For Windows, it would be here: MinGW. Use the installer package.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
downloaded and installed.
how to start this tool and debug code?
You run it from the command prompt: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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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?
Last edited by me001; 09-23-2008 at 10:18 AM.