lohjuyt @ 2022-01-20 15:20:26
#include<stdio.h>
int main()
{
int n,k,a[1001],b[1001];
int sum1=0;
int sum2=0;
int i=1;
int j=1;
int m=1;
scanf("%d %d",&n,&k);
for(m=1;m<=n;m++)
{
if(m%k==0)
a[i]=m;
i++;
sum1=sum1+a[i];
if(m%k!=0)
b[j]=m;
j++;
sum2=sum2+b[j];
}
double aver1,aver2;
aver1=sum1/i;
aver2=sum2/j;
printf("%.1f %.1f",aver1,aver2);
return 0;
}
by coldy_rainy @ 2022-01-20 15:43:06
@lohjuyt
#include<stdio.h>
int main()
{
int n,k,a[1001],b[1001];
int sum1=0;
int sum2=0;
int i=0;
int j=0;
int m;
scanf("%d %d",&n,&k);
for(m=1;m<=n;m++)
{
if(m%k==0)
{
a[i]=m;
sum1=sum1+a[i];
i++;
}
if(m%k!=0)
{
b[j]=m;
sum2=sum2+b[j];
j++;
}
}
double aver1,aver2;
aver1=sum1*1.0/i;
aver2=sum2*1.0/j;
printf("%.1f %.1f",aver1,aver2);
return 0;
}
具体为什么你自己去看吧,我要去打篮球没时间了,明天我再告诉你为啥
by lohjuyt @ 2022-01-20 16:43:26
@penhaochen 好的,谢谢您