Lilindong @ 2024-07-28 21:44:45
#include<stdio.h>
int main()
{
int n,k,i,sum1=0,sum2=0,num1;
double av1,av2;
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++)
{
if(i%k==0)
{
sum1+=i;
num1++;
}
else
sum2+=i;
}
av1=sum1/(num1*1.0);
av2=sum2/((n-num1)*1.0);
printf("%.1lf %.1lf",av1,av2);
return 0;
}
by Jerrycyx @ 2024-07-28 21:49:14
@Lilindong 盲猜没开 long long
+ 1.0*
应该放在 sum1
/sum2
前面
by Lilindong @ 2024-07-31 18:25:24
@Jerrycyx 我按你的改了,为什么还是过不了,我自己编译没问题呀。
#include<stdio.h>
#include<math.h>
int main()
{
long long n,k,i,sum1=0,sum2=0,num1;
double av1,av2;
scanf("%lld%lld",&n,&k);
for(i=1;i<=n;i++)
{
if(i%k==0)
{
sum1+=i;
num1++;
}
else
sum2+=i;
}
av1=1.0*sum1/num1;
av2=1.0*sum2/(n-num1);
printf("%.1lf %.1lf",av1,av2);
return 0;
}
by zfl2011 @ 2024-07-31 21:44:25
@Lilindong 把所有变量改成全局变量,或全赋值为0,num1的值为随机
by zfl2011 @ 2024-07-31 21:49:58
@Lilindong
#include<stdio.h>
#include<math.h>
long long n, k, i, sum1 = 0, sum2 = 0, num1;
double av1, av2;
int main() {
scanf("%lld%lld", &n, &k);
for (i = 1; i <= n; i++) {
if (i % k == 0) {
sum1 += i;
num1++;
} else
sum2 += i;
}
av1 = 1.0 * sum1 / num1;
av2 = 1.0 * sum2 / (n - n"um1);
printf("%.1lf %.1lf", av1, av2);
return 0;
}
by Lilindong @ 2024-08-01 00:04:15
@zfl2011 非常感谢大佬!!!