print fibo big numbers in c++ or c language

后端 未结 6 1230
夕颜
夕颜 2021-01-16 23:39

I write this code for show fibonacci series using recursion.But It not show correctly for n>43 (ex: for n=100 show:-980107325).

#include
#inc         


        
6条回答
  •  广开言路
    2021-01-17 00:17

    The value of fib(100) is so large that it will overflow even a 64 bit number. To operate on such large values, you need to do arbitrary-precision arithmetic. Arbitrary-precision arithmetic is not provided by C nor C++ standard libraries, so you'll need to either implement it yourself or use a library written by someone else.

    For smaller values that do fit your long long, your problem is that you use the wrong printf format specifier. To print a long long, you need to use %lld.

提交回复
热议问题