pdxdsbzl @ 2023-12-24 21:49:55
#include<stdio.h>
int main()
{
int n,k;
scanf("%d%d",&n,&k);
double sum1,sum2;
double p1=0;
double p2=0;
for(int i=1;i<=n;i++)
{
if(i%k==0)
{
sum2+=i;
p2++;
continue;
}
p1++;
sum1+=i;
}
printf("%.1f ",sum2/p2);
printf("%.1f",sum1/p1);
return 0;
}
by HHYQ_07 @ 2023-12-24 22:12:26
@pdxdsbzl 用整型定义,最后运算平均数时乘上 1.0
结果就会自动变成浮点型的
#include<stdio.h>
int main()
{
int n,k;
scanf("%d%d",&n,&k);
int sum1,sum2;
int p1=0;
int p2=0;
for(int i=1;i<=n;i++)
{
if(i%k==0)
{
sum2+=i;
p2++;
continue;
}
p1++;
sum1+=i;
}
printf("%.1f ",1.0*sum2/p2);
printf("%.1f",1.0*sum1/p1);
return 0;
}
求关
by pdxdsbzl @ 2023-12-25 09:04:58
@Voluminousness 关注啦,虽然但是,用这个好像也是WA,,甚至连样例都没过哦
by asdjklqwe123 @ 2023-12-25 10:43:16
把p1和p2变成int型就好了
by pdxdsbzl @ 2023-12-25 10:44:31
@asdjklqwe123 佬佬佬orz解决了!!!
by HHYQ_07 @ 2023-12-25 22:17:48
@pdxdsbzl 抱歉拿C++交的,C的话删去 return 0
就行了
by llhhss @ 2024-09-05 21:29:57
@pdxdsbzl
int main()
{
int n,k;
scanf("%d%d",&n,&k);
double sum1,sum2;
double p1=0;
double p2=0;
for(int i=1;i<=n;i++)
{
if(i%k==0)
{
sum2+=i;
p2++;
continue;
}
p1++;
sum1+=i;
}
printf("%.1f ",sum2/p2);
cout<<" ";
printf("%.1f",sum1/p1);
return 0;
}```