Public bug reported:
I use g++ (Ubuntu 4.3.3-5ubuntu4) 4.3.3
The following source code produces a wrong output:
#include <iostream>
using namespace std;
int counter = 0;
int fibonacci (int n) {
counter++;
if ( n <= 1) return n ;
return (fibonacci(n-1) + fibonacci(n-2));
}
int main() {
cout << "fibonacci(20) = " << fibonacci(20) << " --> " << counter << "
chiamate! (compless. espon.)" << endl;
return 0;
}
The output is:
fibonacci(20) = 6765 --> 0 chiamate! (compless. espon.)
Of course, the correct output should be:
fibonacci(20) = 6765 --> 21891 chiamate! (compless. espon.)
The same source code, compiled by Dev-C++ (on a Windows machine),
produces the second output.
I hope you can solve the problem,
thank you,
Francesco Galgani
** Affects: gcc-4.3 (Ubuntu)
Importance: Undecided
Status: New
** Tags: cout g++
--
"cout" -> strange behaviour
https://bugs.launchpad.net/bugs/404572
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs