printfscanf_ @ 2021-12-11 16:37:06
#include <stdio.h>
int main()
{
int n,k;
int a[10001],b[10001];
int at=0,bt=0;
double suma=0.0;
double sumb=0.0;
double ap,bp;
int i;
scanf("%d %d",&n,&k);
for(i=1;i<n;i++)
{
if(i%k==0)
{
a[at]=i;
at++;
}
else
{
b[bt]=i;
bt++;
}
}
for(i=0;i<at;i++)
{
suma=suma+a[i];
}
for(i=0;i<bt;i++)
{
sumb=sumb+b[i];
}
ap=suma/at;
bp=sumb/bt;
printf("%.1f %.1f",ap,bp);
return 0;
}
by lsj2009 @ 2021-12-11 16:47:26
@printfscanf_ 将从 1 到 n 之间的所有正整数可以分为两类
注意,是for(i=1;i<=n;i++)
by lsj2009 @ 2021-12-11 16:49:32
by printfscanf_ @ 2021-12-11 16:50:41
@lsj2009 改完之后还是不对啊,还是零分
by Fresca @ 2021-12-11 17:07:21
@printfscanf_ 你交的后面写的是
bp=sumb/at;
by printfscanf_ @ 2021-12-11 17:36:15
#include <stdio.h>
int main()
{
int n,k;
int a[10001],b[10001];
int at=0,bt=0;
float suma=0.0;
float sumb=0.0;
float ap,bp;
int i;
scanf("%d %d",&n,&k);
for(i=1;i<=n;i++)
{
if(i%k==0)
{
a[at]=i;
at++;
}
else
{
b[bt]=i;
bt++;
}
}
for(i=0;i<at;i++)
{
suma=suma+a[i];
}
for(i=0;i<bt;i++)
{
sumb=sumb+b[i];
}
ap=suma/at;
bp=sumb/bt;
printf("%.1f %.1f",ap,bp);
return 0;
}
@Fresco 现在是这样变成40分了
by Fresca @ 2021-12-11 21:16:44
@printfscanf_ 不要用float,精度比double低
by printfscanf_ @ 2021-12-11 21:23:53
@Fresco 谢谢