求教!如何改进程序一小点,改变计算结果一大点?
已知程序:#include <stdio.h>
main()
{
int m[7]={7,-6,5,4,3,2,1};
int n[7]={22,-6,5,4,3,2,1};
char a[7]={0};
int i,j, mc, nc, mmax,nmax;
char sm[256], sn[256], smc[1024], snc[1024];
printf("m[7]={7,-6,5,4,3,2,1}\n");
printf("n[7]={22,-6,5,4,3,2,1}\n\n");
for (i=0; i<7; i++)
{
for (j=1; j<=i; j++)
a[j] = 1;
mmax = m[0];
nmax = n[0];
while (1)
{
mc = m[0];
nc = n[0];
sprintf(sm, "%s", "m0");
sprintf(sn, "%s", "n0");
sprintf(smc, "%d", m[0]);
sprintf(snc, "%d", n[0]);
for (j=1; j<=i; j++)
{
if (a[j])
{
mc += m[j];
nc += n[j];
sprintf(sm, "%s+m%d", sm,j);
sprintf(sn, "%s+n%d", sn,j);
sprintf(smc, "%s+%d", smc,m[j]);
sprintf(snc, "%s+%d", snc,n[j]);
}
else
{
mc -= m[j];
nc -= n[j];
sprintf(sm, "%s-m%d", sm,j);
sprintf(sn, "%s-n%d", sn,j);
sprintf(smc, "%s-%d", smc,m[j]);
sprintf(snc, "%s-%d", snc,n[j]);
}
}
if (mc > mmax)
{
mmax = mc;
nmax = nc;
}
printf("(%s)/(%s) = ", sm,sn);
printf("(%s)/(%s) = ", smc,snc);
printf("%d/%d = ", mc,nc);
if (nc != 0)
printf("%lf\n", (double)mc/nc);
else
printf("∞\n");
for (j=i; j>0; j--)
{
if (a[j])
{
a[j] = 0;
break;
}
}
if (j == 0)
break;
for (++j; j<=i; j++)
a[j] = 1;
}
if (nmax != 0)
printf("最大值%d/%d = %lf\n", mmax,nmax,(double)mmax/nmax);
printf("\n===============================\n");
}
}
运行结果:
m[7]={7,-6,5,4,3,2,1}
n[7]={22,-6,5,4,3,2,1}
(m0)/(n0) = (7)/(22) = 7/22 = 0.318182
最大值7/22 = 0.318182
===============================
(m0+m1)/(n0+n1) = (7+-6)/(22+-6) = 1/16 = 0.062500
(m0-m1)/(n0-n1) = (7--6)/(22--6) = 13/28 = 0.464286
最大值13/28 = 0.464286
===============================
(m0+m1+m2)/(n0+n1+n2) = (7+-6+5)/(22+-6+5) = 6/21 = 0.285714
(m0+m1-m2)/(n0+n1-n2) = (7+-6-5)/(22+-6-5) = -4/11 = -0.363636
(m0-m1+m2)/(n0-n1+n2) = (7--6+5)/(22--6+5) = 18/33 = 0.545455
(m0-m1-m2)/(n0-n1-n2) = (7--6-5)/(22--6-5) = 8/23 = 0.347826
最大值18/33 = 0.545455
===============================
(m0+m1+m2+m3)/(n0+n1+n2+n3) = (7+-6+5+4)/(22+-6+5+4) = 10/25 = 0.400000
(m0+m1+m2-m3)/(n0+n1+n2-n3) = (7+-6+5-4)/(22+-6+5-4) = 2/17 = 0.117647
(m0+m1-m2+m3)/(n0+n1-n2+n3) = (7+-6-5+4)/(22+-6-5+4) = 0/15 = 0.000000
(m0+m1-m2-m3)/(n0+n1-n2-n3) = (7+-6-5-4)/(22+-6-5-4) = -8/7 = -1.142857
(m0-m1+m2+m3)/(n0-n1+n2+n3) = (7--6+5+4)/(22--6+5+4) = 22/37 = 0.594595
(m0-m1+m2-m3)/(n0-n1+n2-n3) = (7--6+5-4)/(22--6+5-4) = 14/29 = 0.482759
(m0-m1-m2+m3)/(n0-n1-n2+n3) = (7--6-5+4)/(22--6-5+4) = 12/27 = 0.444444
(m0-m1-m2-m3)/(n0-n1-n2-n3) = (7--6-5-4)/(22--6-5-4) = 4/19 = 0.210526
最大值22/37 = 0.594595
===============================
(m0+m1+m2+m3+m4)/(n0+n1+n2+n3+n4) = (7+-6+5+4+3)/(22+-6+5+4+3) = 13/28 = 0.46428
6
(m0+m1+m2+m3-m4)/(n0+n1+n2+n3-n4) = (7+-6+5+4-3)/(22+-6+5+4-3) = 7/22 = 0.318182
(m0+m1+m2-m3+m4)/(n0+n1+n2-n3+n4) = (7+-6+5-4+3)/(22+-6+5-4+3) = 5/20 = 0.250000
(m0+m1+m2-m3-m4)/(n0+n1+n2-n3-n4) = (7+-6+5-4-3)/(22+-6+5-4-3) = -1/14 = -0.0714
29
(m0+m1-m2+m3+m4)/(n0+n1-n2+n3+n4) = (7+-6-5+4+3)/(22+-6-5+4+3) = 3/18 = 0.166667
(m0+m1-m2+m3-m4)/(n0+n1-n2+n3-n4) = (7+-6-5+4-3)/(22+-6-5+4-3) = -3/12 = -0.2500
00
(m0+m1-m2-m3+m4)/(n0+n1-n2-n3+n4) = (7+-6-5-4+3)/(22+-6-5-4+3) = -5/10 = -0.5000
00
(m0+m1-m2-m3-m4)/(n0+n1-n2-n3-n4) = (7+-6-5-4-3)/(22+-6-5-4-3) = -11/4 = -2.7500
00
(m0-m1+m2+m3+m4)/(n0-n1+n2+n3+n4) = (7--6+5+4+3)/(22--6+5+4+3) = 25/40 = 0.62500
0
(m0-m1+m2+m3-m4)/(n0-n1+n2+n3-n4) = (7--6+5+4-3)/(22--6+5+4-3) = 19/34 = 0.55882
4
(m0-m1+m2-m3+m4)/(n0-n1+n2-n3+n4) = (7--6+5-4+3)/(22--6+5-4+3) = 17/32 = 0.53125
0
(m0-m1+m2-m3-m4)/(n0-n1+n2-n3-n4) = (7--6+5-4-3)/(22--6+5-4-3) = 11/26 = 0.42307
7
(m0-m1-m2+m3+m4)/(n0-n1-n2+n3+n4) = (7--6-5+4+3)/(22--6-5+4+3) = 15/30 = 0.50000
0
(m0-m1-m2+m3-m4)/(n0-n1-n2+n3-n4) = (7--6-5+4-3)/(22--6-5+4-3) = 9/24 = 0.375000
(m0-m1-m2-m3+m4)/(n0-n1-n2-n3+n4) = (7--6-5-4+3)/(22--6-5-4+3) = 7/22 = 0.318182
(m0-m1-m2-m3-m4)/(n0-n1-n2-n3-n4) = (7--6-5-4-3)/(22--6-5-4-3) = 1/16 = 0.062500
最大值25/40 = 0.625000
===============================
(m0+m1+m2+m3+m4+m5)/(n0+n1+n2+n3+n4+n5) = (7+-6+5+4+3+2)/(22+-6+5+4+3+2) = 15/30
= 0.500000
(m0+m1+m2+m3+m4-m5)/(n0+n1+n2+n3+n4-n5) = (7+-6+5+4+3-2)/(22+-6+5+4+3-2) = 11/26
= 0.423077
(m0+m1+m2+m3-m4+m5)/(n0+n1+n2+n3-n4+n5) = (7+-6+5+4-3+2)/(22+-6+5+4-3+2) = 9/24
= 0.375000
(m0+m1+m2+m3-m4-m5)/(n0+n1+n2+n3-n4-n5) = (7+-6+5+4-3-2)/(22+-6+5+4-3-2) = 5/20
= 0.250000
(m0+m1+m2-m3+m4+m5)/(n0+n1+n2-n3+n4+n5) = (7+-6+5-4+3+2)/(22+-6+5-4+3+2) = 7/22
= 0.318182
(m0+m1+m2-m3+m4-m5)/(n0+n1+n2-n3+n4-n5) = (7+-6+5-4+3-2)/(22+-6+5-4+3-2) = 3/18
= 0.166667
(m0+m1+m2-m3-m4+m5)/(n0+n1+n2-n3-n4+n5) = (7+-6+5-4-3+2)/(22+-6+5-4-3+2) = 1/16
= 0.062500
(m0+m1+m2-m3-m4-m5)/(n0+n1+n2-n3-n4-n5) = (7+-6+5-4-3-2)/(22+-6+5-4-3-2) = -3/12
= -0.250000
(m0+m1-m2+m3+m4+m5)/(n0+n1-n2+n3+n4+n5) = (7+-6-5+4+3+2)/(22+-6-5+4+3+2) = 5/20
= 0.250000
(m0+m1-m2+m3+m4-m5)/(n0+n1-n2+n3+n4-n5) = (7+-6-5+4+3-2)/(22+-6-5+4+3-2) = 1/16
= 0.062500
(m0+m1-m2+m3-m4+m5)/(n0+n1-n2+n3-n4+n5) = (7+-6-5+4-3+2)/(22+-6-5+4-3+2) = -1/14
= -0.071429
(m0+m1-m2+m3-m4-m5)/(n0+n1-n2+n3-n4-n5) = (7+-6-5+4-3-2)/(22+-6-5+4-3-2) = -5/10
= -0.500000
(m0+m1-m2-m3+m4+m5)/(n0+n1-n2-n3+n4+n5) = (7+-6-5-4+3+2)/(22+-6-5-4+3+2) = -3/12
= -0.250000
(m0+m1-m2-m3+m4-m5)/(n0+n1-n2-n3+n4-n5) = (7+-6-5-4+3-2)/(22+-6-5-4+3-2) = -7/8
= -0.875000
(m0+m1-m2-m3-m4+m5)/(n0+n1-n2-n3-n4+n5) = (7+-6-5-4-3+2)/(22+-6-5-4-3+2) = -9/6
= -1.500000
(m0+m1-m2-m3-m4-m5)/(n0+n1-n2-n3-n4-n5) = (7+-6-5-4-3-2)/(22+-6-5-4-3-2) = -13/2
= -6.500000
(m0-m1+m2+m3+m4+m5)/(n0-n1+n2+n3+n4+n5) = (7--6+5+4+3+2)/(22--6+5+4+3+2) = 27/42
= 0.642857
(m0-m1+m2+m3+m4-m5)/(n0-n1+n2+n3+n4-n5) = (7--6+5+4+3-2)/(22--6+5+4+3-2) = 23/38
= 0.605263
(m0-m1+m2+m3-m4+m5)/(n0-n1+n2+n3-n4+n5) = (7--6+5+4-3+2)/(22--6+5+4-3+2) = 21/36
= 0.583333
(m0-m1+m2+m3-m4-m5)/(n0-n1+n2+n3-n4-n5) = (7--6+5+4-3-2)/(22--6+5+4-3-2) = 17/32
= 0.531250
(m0-m1+m2-m3+m4+m5)/(n0-n1+n2-n3+n4+n5) = (7--6+5-4+3+2)/(22--6+5-4+3+2) = 19/34
= 0.558824
(m0-m1+m2-m3+m4-m5)/(n0-n1+n2-n3+n4-n5) = (7--6+5-4+3-2)/(22--6+5-4+3-2) = 15/30
= 0.500000
(m0-m1+m2-m3-m4+m5)/(n0-n1+n2-n3-n4+n5) = (7--6+5-4-3+2)/(22--6+5-4-3+2) = 13/28
= 0.464286
(m0-m1+m2-m3-m4-m5)/(n0-n1+n2-n3-n4-n5) = (7--6+5-4-3-2)/(22--6+5-4-3-2) = 9/24
= 0.375000
(m0-m1-m2+m3+m4+m5)/(n0-n1-n2+n3+n4+n5) = (7--6-5+4+3+2)/(22--6-5+4+3+2) = 17/32
= 0.531250
(m0-m1-m2+m3+m4-m5)/(n0-n1-n2+n3+n4-n5) = (7--6-5+4+3-2)/(22--6-5+4+3-2) = 13/28
= 0.464286
(m0-m1-m2+m3-m4+m5)/(n0-n1-n2+n3-n4+n5) = (7--6-5+4-3+2)/(22--6-5+4-3+2) = 11/26
= 0.423077
(m0-m1-m2+m3-m4-m5)/(n0-n1-n2+n3-n4-n5) = (7--6-5+4-3-2)/(22--6-5+4-3-2) = 7/22
= 0.318182
(m0-m1-m2-m3+m4+m5)/(n0-n1-n2-n3+n4+n5) = (7--6-5-4+3+2)/(22--6-5-4+3+2) = 9/24
= 0.375000
(m0-m1-m2-m3+m4-m5)/(n0-n1-n2-n3+n4-n5) = (7--6-5-4+3-2)/(22--6-5-4+3-2) = 5/20
= 0.250000
(m0-m1-m2-m3-m4+m5)/(n0-n1-n2-n3-n4+n5) = (7--6-5-4-3+2)/(22--6-5-4-3+2) = 3/18
= 0.166667
(m0-m1-m2-m3-m4-m5)/(n0-n1-n2-n3-n4-n5) = (7--6-5-4-3-2)/(22--6-5-4-3-2) = -1/14
= -0.071429
最大值27/42 = 0.642857
===============================
(m0+m1+m2+m3+m4+m5+m6)/(n0+n1+n2+n3+n4+n5+n6) = (7+-6+5+4+3+2+1)/(22+-6+5+4+3+2+
1) = 16/31 = 0.516129
(m0+m1+m2+m3+m4+m5-m6)/(n0+n1+n2+n3+n4+n5-n6) = (7+-6+5+4+3+2-1)/(22+-6+5+4+3+2-
1) = 14/29 = 0.482759
(m0+m1+m2+m3+m4-m5+m6)/(n0+n1+n2+n3+n4-n5+n6) = (7+-6+5+4+3-2+1)/(22+-6+5+4+3-2+
1) = 12/27 = 0.444444
(m0+m1+m2+m3+m4-m5-m6)/(n0+n1+n2+n3+n4-n5-n6) = (7+-6+5+4+3-2-1)/(22+-6+5+4+3-2-
1) = 10/25 = 0.400000
(m0+m1+m2+m3-m4+m5+m6)/(n0+n1+n2+n3-n4+n5+n6) = (7+-6+5+4-3+2+1)/(22+-6+5+4-3+2+
1) = 10/25 = 0.400000
(m0+m1+m2+m3-m4+m5-m6)/(n0+n1+n2+n3-n4+n5-n6) = (7+-6+5+4-3+2-1)/(22+-6+5+4-3+2-
1) = 8/23 = 0.347826
(m0+m1+m2+m3-m4-m5+m6)/(n0+n1+n2+n3-n4-n5+n6) = (7+-6+5+4-3-2+1)/(22+-6+5+4-3-2+
1) = 6/21 = 0.285714
(m0+m1+m2+m3-m4-m5-m6)/(n0+n1+n2+n3-n4-n5-n6) = (7+-6+5+4-3-2-1)/(22+-6+5+4-3-2-
1) = 4/19 = 0.210526
(m0+m1+m2-m3+m4+m5+m6)/(n0+n1+n2-n3+n4+n5+n6) = (7+-6+5-4+3+2+1)/(22+-6+5-4+3+2+
1) = 8/23 = 0.347826
(m0+m1+m2-m3+m4+m5-m6)/(n0+n1+n2-n3+n4+n5-n6) = (7+-6+5-4+3+2-1)/(22+-6+5-4+3+2-
1) = 6/21 = 0.285714
(m0+m1+m2-m3+m4-m5+m6)/(n0+n1+n2-n3+n4-n5+n6) = (7+-6+5-4+3-2+1)/(22+-6+5-4+3-2+
1) = 4/19 = 0.210526
(m0+m1+m2-m3+m4-m5-m6)/(n0+n1+n2-n3+n4-n5-n6) = (7+-6+5-4+3-2-1)/(22+-6+5-4+3-2-
1) = 2/17 = 0.117647
(m0+m1+m2-m3-m4+m5+m6)/(n0+n1+n2-n3-n4+n5+n6) = (7+-6+5-4-3+2+1)/(22+-6+5-4-3+2+
1) = 2/17 = 0.117647
(m0+m1+m2-m3-m4+m5-m6)/(n0+n1+n2-n3-n4+n5-n6) = (7+-6+5-4-3+2-1)/(22+-6+5-4-3+2-
1) = 0/15 = 0.000000
(m0+m1+m2-m3-m4-m5+m6)/(n0+n1+n2-n3-n4-n5+n6) = (7+-6+5-4-3-2+1)/(22+-6+5-4-3-2+
1) = -2/13 = -0.153846
(m0+m1+m2-m3-m4-m5-m6)/(n0+n1+n2-n3-n4-n5-n6) = (7+-6+5-4-3-2-1)/(22+-6+5-4-3-2-
1) = -4/11 = -0.363636
(m0+m1-m2+m3+m4+m5+m6)/(n0+n1-n2+n3+n4+n5+n6) = (7+-6-5+4+3+2+1)/(22+-6-5+4+3+2+
1) = 6/21 = 0.285714
(m0+m1-m2+m3+m4+m5-m6)/(n0+n1-n2+n3+n4+n5-n6) = (7+-6-5+4+3+2-1)/(22+-6-5+4+3+2-
1) = 4/19 = 0.210526
(m0+m1-m2+m3+m4-m5+m6)/(n0+n1-n2+n3+n4-n5+n6) = (7+-6-5+4+3-2+1)/(22+-6-5+4+3-2+
1) = 2/17 = 0.117647
(m0+m1-m2+m3+m4-m5-m6)/(n0+n1-n2+n3+n4-n5-n6) = (7+-6-5+4+3-2-1)/(22+-6-5+4+3-2-
1) = 0/15 = 0.000000
(m0+m1-m2+m3-m4+m5+m6)/(n0+n1-n2+n3-n4+n5+n6) = (7+-6-5+4-3+2+1)/(22+-6-5+4-3+2+
1) = 0/15 = 0.000000
(m0+m1-m2+m3-m4+m5-m6)/(n0+n1-n2+n3-n4+n5-n6) = (7+-6-5+4-3+2-1)/(22+-6-5+4-3+2-
1) = -2/13 = -0.153846
(m0+m1-m2+m3-m4-m5+m6)/(n0+n1-n2+n3-n4-n5+n6) = (7+-6-5+4-3-2+1)/(22+-6-5+4-3-2+
1) = -4/11 = -0.363636
(m0+m1-m2+m3-m4-m5-m6)/(n0+n1-n2+n3-n4-n5-n6) = (7+-6-5+4-3-2-1)/(22+-6-5+4-3-2-
1) = -6/9 = -0.666667
(m0+m1-m2-m3+m4+m5+m6)/(n0+n1-n2-n3+n4+n5+n6) = (7+-6-5-4+3+2+1)/(22+-6-5-4+3+2+
1) = -2/13 = -0.153846
(m0+m1-m2-m3+m4+m5-m6)/(n0+n1-n2-n3+n4+n5-n6) = (7+-6-5-4+3+2-1)/(22+-6-5-4+3+2-
1) = -4/11 = -0.363636
(m0+m1-m2-m3+m4-m5+m6)/(n0+n1-n2-n3+n4-n5+n6) = (7+-6-5-4+3-2+1)/(22+-6-5-4+3-2+
1) = -6/9 = -0.666667
(m0+m1-m2-m3+m4-m5-m6)/(n0+n1-n2-n3+n4-n5-n6) = (7+-6-5-4+3-2-1)/(22+-6-5-4+3-2-
1) = -8/7 = -1.142857
(m0+m1-m2-m3-m4+m5+m6)/(n0+n1-n2-n3-n4+n5+n6) = (7+-6-5-4-3+2+1)/(22+-6-5-4-3+2+
1) = -8/7 = -1.142857
(m0+m1-m2-m3-m4+m5-m6)/(n0+n1-n2-n3-n4+n5-n6) = (7+-6-5-4-3+2-1)/(22+-6-5-4-3+2-
1) = -10/5 = -2.000000
(m0+m1-m2-m3-m4-m5+m6)/(n0+n1-n2-n3-n4-n5+n6) = (7+-6-5-4-3-2+1)/(22+-6-5-4-3-2+
1) = -12/3 = -4.000000
(m0+m1-m2-m3-m4-m5-m6)/(n0+n1-n2-n3-n4-n5-n6) = (7+-6-5-4-3-2-1)/(22+-6-5-4-3-2-
1) = -14/1 = -14.000000
(m0-m1+m2+m3+m4+m5+m6)/(n0-n1+n2+n3+n4+n5+n6) = (7--6+5+4+3+2+1)/(22--6+5+4+3+2+
1) = 28/43 = 0.651163
(m0-m1+m2+m3+m4+m5-m6)/(n0-n1+n2+n3+n4+n5-n6) = (7--6+5+4+3+2-1)/(22--6+5+4+3+2-
1) = 26/41 = 0.634146
(m0-m1+m2+m3+m4-m5+m6)/(n0-n1+n2+n3+n4-n5+n6) = (7--6+5+4+3-2+1)/(22--6+5+4+3-2+
1) = 24/39 = 0.615385
(m0-m1+m2+m3+m4-m5-m6)/(n0-n1+n2+n3+n4-n5-n6) = (7--6+5+4+3-2-1)/(22--6+5+4+3-2-
1) = 22/37 = 0.594595
(m0-m1+m2+m3-m4+m5+m6)/(n0-n1+n2+n3-n4+n5+n6) = (7--6+5+4-3+2+1)/(22--6+5+4-3+2+
1) = 22/37 = 0.594595
(m0-m1+m2+m3-m4+m5-m6)/(n0-n1+n2+n3-n4+n5-n6) = (7--6+5+4-3+2-1)/(22--6+5+4-3+2-
1) = 20/35 = 0.571429
(m0-m1+m2+m3-m4-m5+m6)/(n0-n1+n2+n3-n4-n5+n6) = (7--6+5+4-3-2+1)/(22--6+5+4-3-2+
1) = 18/33 = 0.545455
(m0-m1+m2+m3-m4-m5-m6)/(n0-n1+n2+n3-n4-n5-n6) = (7--6+5+4-3-2-1)/(22--6+5+4-3-2-
1) = 16/31 = 0.516129
(m0-m1+m2-m3+m4+m5+m6)/(n0-n1+n2-n3+n4+n5+n6) = (7--6+5-4+3+2+1)/(22--6+5-4+3+2+
1) = 20/35 = 0.571429
(m0-m1+m2-m3+m4+m5-m6)/(n0-n1+n2-n3+n4+n5-n6) = (7--6+5-4+3+2-1)/(22--6+5-4+3+2-
1) = 18/33 = 0.545455
(m0-m1+m2-m3+m4-m5+m6)/(n0-n1+n2-n3+n4-n5+n6) = (7--6+5-4+3-2+1)/(22--6+5-4+3-2+
1) = 16/31 = 0.516129
(m0-m1+m2-m3+m4-m5-m6)/(n0-n1+n2-n3+n4-n5-n6) = (7--6+5-4+3-2-1)/(22--6+5-4+3-2-
1) = 14/29 = 0.482759
(m0-m1+m2-m3-m4+m5+m6)/(n0-n1+n2-n3-n4+n5+n6) = (7--6+5-4-3+2+1)/(22--6+5-4-3+2+
1) = 14/29 = 0.482759
(m0-m1+m2-m3-m4+m5-m6)/(n0-n1+n2-n3-n4+n5-n6) = (7--6+5-4-3+2-1)/(22--6+5-4-3+2-
1) = 12/27 = 0.444444
(m0-m1+m2-m3-m4-m5+m6)/(n0-n1+n2-n3-n4-n5+n6) = (7--6+5-4-3-2+1)/(22--6+5-4-3-2+
1) = 10/25 = 0.400000
(m0-m1+m2-m3-m4-m5-m6)/(n0-n1+n2-n3-n4-n5-n6) = (7--6+5-4-3-2-1)/(22--6+5-4-3-2-
1) = 8/23 = 0.347826
(m0-m1-m2+m3+m4+m5+m6)/(n0-n1-n2+n3+n4+n5+n6) = (7--6-5+4+3+2+1)/(22--6-5+4+3+2+
1) = 18/33 = 0.545455
(m0-m1-m2+m3+m4+m5-m6)/(n0-n1-n2+n3+n4+n5-n6) = (7--6-5+4+3+2-1)/(22--6-5+4+3+2-
1) = 16/31 = 0.516129
(m0-m1-m2+m3+m4-m5+m6)/(n0-n1-n2+n3+n4-n5+n6) = (7--6-5+4+3-2+1)/(22--6-5+4+3-2+
1) = 14/29 = 0.482759
(m0-m1-m2+m3+m4-m5-m6)/(n0-n1-n2+n3+n4-n5-n6) = (7--6-5+4+3-2-1)/(22--6-5+4+3-2-
1) = 12/27 = 0.444444
(m0-m1-m2+m3-m4+m5+m6)/(n0-n1-n2+n3-n4+n5+n6) = (7--6-5+4-3+2+1)/(22--6-5+4-3+2+
1) = 12/27 = 0.444444
(m0-m1-m2+m3-m4+m5-m6)/(n0-n1-n2+n3-n4+n5-n6) = (7--6-5+4-3+2-1)/(22--6-5+4-3+2-
1) = 10/25 = 0.400000
(m0-m1-m2+m3-m4-m5+m6)/(n0-n1-n2+n3-n4-n5+n6) = (7--6-5+4-3-2+1)/(22--6-5+4-3-2+
1) = 8/23 = 0.347826
(m0-m1-m2+m3-m4-m5-m6)/(n0-n1-n2+n3-n4-n5-n6) = (7--6-5+4-3-2-1)/(22--6-5+4-3-2-
1) = 6/21 = 0.285714
(m0-m1-m2-m3+m4+m5+m6)/(n0-n1-n2-n3+n4+n5+n6) = (7--6-5-4+3+2+1)/(22--6-5-4+3+2+
1) = 10/25 = 0.400000
(m0-m1-m2-m3+m4+m5-m6)/(n0-n1-n2-n3+n4+n5-n6) = (7--6-5-4+3+2-1)/(22--6-5-4+3+2-
1) = 8/23 = 0.347826
(m0-m1-m2-m3+m4-m5+m6)/(n0-n1-n2-n3+n4-n5+n6) = (7--6-5-4+3-2+1)/(22--6-5-4+3-2+
1) = 6/21 = 0.285714
(m0-m1-m2-m3+m4-m5-m6)/(n0-n1-n2-n3+n4-n5-n6) = (7--6-5-4+3-2-1)/(22--6-5-4+3-2-
1) = 4/19 = 0.210526
(m0-m1-m2-m3-m4+m5+m6)/(n0-n1-n2-n3-n4+n5+n6) = (7--6-5-4-3+2+1)/(22--6-5-4-3+2+
1) = 4/19 = 0.210526
(m0-m1-m2-m3-m4+m5-m6)/(n0-n1-n2-n3-n4+n5-n6) = (7--6-5-4-3+2-1)/(22--6-5-4-3+2-
1) = 2/17 = 0.117647
(m0-m1-m2-m3-m4-m5+m6)/(n0-n1-n2-n3-n4-n5+n6) = (7--6-5-4-3-2+1)/(22--6-5-4-3-2+
1) = 0/15 = 0.000000
(m0-m1-m2-m3-m4-m5-m6)/(n0-n1-n2-n3-n4-n5-n6) = (7--6-5-4-3-2-1)/(22--6-5-4-3-2-
1) = -2/13 = -0.153846
最大值28/43 = 0.651163
===============================
Press any key to continue
如何改进程序,计算出:
m[7]={7,-6,5,4,3,2,1}
n[7]={22,-6,5,4,3,2,1}
1:计算:排序找出m[0],m[1],m[2],m[3],m[4],m[5],m[6],中的最大值;
输出:(当m[i]是最大值,且n[i]!=0时),m[i]/n[i]; (例如:7最大,22不等于0,输出7/22=0.318182;)
2:计算:排序找出m[0]+m[1],m[1]+m[2],m[2]+m[3],m[3]+m[4],m[4]+m[5],m[5]+m[6],中的最大值;
输出:(当m[i]+m[i+1]是最大值,且n[i]+n[i+1]!=0时),(m[i]+m[i+1])/(n[i]+n[i+1]);
计算:排序找出m[0]-m[1],m[1]-m[2],m[2]-m[3],m[3]-m[4],m[4]-m[5],m[5]-m[6],中的最大值;
输出:(当m[i]-m[i+1]是最大值,且n[i]-n[i+1]!=0时),(m[i]-m[i+1])/(n[i]-n[i+1]);
3:
4:
5:
6:
7:
[此贴子已经被作者于2017-2-23 10:30编辑过]