91
Example Code / Re: Fibonacci, with bigger numbers
« Last post by fredericopissarra on November 28, 2023, 05:30:49 PM »To be fair, using 'bc' this way isn't correct as well... Here's a simple code using 'libgmp' to illustrate:
Code: [Select]
// fib.c
//
// cc -O2 -o fib fib.c -lgmp
//
#include <gmp.h>
// Prints all fibonacci numbers from the first to the 5000th.
int main(void)
{
mpz_t n;
mpz_init( n );
for ( unsigned int i = 1; i <= 5000; i++ )
{
mpz_fib_ui( n, i );
gmp_printf( "%u: %Zd\n", i, n );
}
mpz_clear( n );
}
The 5000th number is 3878968454388325633701916308325905312082127714646245106160597214895550139044037097010822916462210669479293452858882973813483102008954982940361430156911478938364216563944106910214505634133706558656238254656700712525929903854933813928836378347518908762970712033337052923107693008518093849801803847813996748881765554653788291644268912980384613778969021502293082475666346224923071883324803280375039130352903304505842701147635242270210934637699104006714174883298422891491273104054328753298044273676822977244987749874555691907703880637046832794811358973739993110106219308149018570815397854379195305617510761053075688783766033667355445258844886241619210553457493675897849027988234351023599844663934853256411952221859563060475364645470760330902420806382584929156452876291575759142343809142302917491088984155209854432486594079793571316841692868039545309545388698114665082066862897420639323438488465240988742395873801976993820317174208932265468879364002630797780058759129671389634214252579116872755600360311370547754724604639987588046985178408674382863125.