谢谢,弄出来,么么哒
以下是引用rjsp在2016-3-21 11:22:19的发言:
换个公式,s(n) = s(n-2) + s(n-1) + 1; s(-1)=0, s(0)=0
#include <stdio.h>
// s(n) = s(n-2) + s(n-1) + 1; s(-1)=0, s(0)=0
void fibonacci_avg( unsigned n )
{
// 斐波那契数列前n项之和
unsigned a[6]={0}, b[6]={0};
for( unsigned m=0; m!=n; ++m )
{
unsigned carry = 1;
for( size_t i=0; i!=6; ++i )
{
carry += a + b;
a = b;
b = carry%10000000;
carry /= 10000000;
}
}
// 平均值
unsigned carry = 0;
for( size_t i=0; i!=6; ++i )
{
carry = carry*10000000 + b[5-i];
a = carry/n;
carry %= n;
}
// 十进制输出
printf( "%u%07u%07u%07u%07u%06u%g\n", a[0],a[1],a[2],a[3],a[4],a[5]/10,a[5]%10+carry*1.0/n );
return;
}
int main( void )
{
fibonacci_avg( 200 );
return 0;
}输出