你是只要7个数的64个结果,还是要k个数的2^(k-1)个结果?
程序代码:
#include <stdio.h>
#include <assert.h>
#include <limits.h>
void foo( unsigned k, const double m[], const double n[] )
{
assert( k!=0 && k<sizeof(k)*CHAR_BIT );
for( unsigned i=0; i!=1u<<(k-1); ++i )
{
#ifndef NDEBUG
printf( "(m0" );
for( unsigned j=1; j!=k; ++j )
printf( "%cm%u", "+-"[(i&(1u<<(k-j-1)))!=0], j );
printf( ")/(n0" );
for( unsigned j=1; j!=k; ++j )
printf( "%cn%u", "+-"[(i&(1u<<(k-j-1)))!=0], j );
printf( ") = " );
#endif
//#ifndef NDEBUG
// printf( "(%g", m[0] );
// for( unsigned j=1; j!=k; ++j )
// printf( "%c%g", "+-"[(i&(1u<<(k-j-1)))!=0], m[j] );
// printf( ")/(%g", n[0] );
// for( unsigned j=1; j!=k; ++j )
// printf( "%c%g", "+-"[(i&(1u<<(k-j-1)))!=0], n[j] );
// printf( ") = " );
//#endif
double a=m[0], b=n[0];
for( unsigned j=1; j!=k; ++j )
{
a += m[j] * ( (i&(1u<<(k-j-1)))==0 ? +1 : -1 );
b += n[j] * ( (i&(1u<<(k-j-1)))==0 ? +1 : -1 );
}
printf( "%+lf\n", 0.0+a/b );
}
}
int main( void )
{
double m[] = { 1, 2, 3, 4, 5, 6, 7 };
double n[] = { 8, 9, 10, 11, 12, 13, 14 };
foo( 7, m, n );
return 0;
}