huangboyue @ 2022-10-29 13:30:50
#include<iostream>
using namespace std;
int main()
{
int n,k,cnta=0,cntb=0,a=0,b=0;
float a1,b1;
cin>>n>>k;
for(int i=1;i<=n;i++)
{
if(i%k==0)
{
cnta++;
a=a+i;
}
else if(i%k!=0)
{
cntb++;
b=b+i;
}
}
a1=(a/cnta);
b1=(b/cntb);
printf("%.1lf %.1lf",a1,b1);
}
by cute_overmind @ 2022-10-29 13:39:47
@huangboyue
#include <iostream>
#include <cstdio>
using namespace std;
int main ()
{
int n , m , sum = 0;
cin >> n >> m;
for (int i = m; i <= n; i += m)
sum += i;
printf ("%.1f ", double(sum) / (n / m));
sum = (1 + n) * n / 2 - sum;
printf ("%.1f\n", double(sum) / (n - n / m));
return 0;
}
by cute_overmind @ 2022-10-29 13:41:00
这位兄弟,你忘加头文件了
by WZWZWZWY @ 2022-10-29 13:42:38
@Pikacu
这不是问题的重点吧……
by WZWZWZWY @ 2022-10-29 13:45:47
@huangboyue
a1=(a/cnta);中,a是整数,cnta也是整数,相除的结果也会是整数,你把a乘1.0试试
也就是a1=(1.0*a/cnta);
by cute_overmind @ 2022-10-29 13:49:34
@WZRYWZWY 但是你不加头文件是较大的错误,你没有头文件就什么都没了
by cute_overmind @ 2022-10-29 13:51:05
@WZRYWZWY 但你说的确实有道理
by WZWZWZWY @ 2022-10-29 14:06:13
@Pikacu
这确实是个好习惯,只是你没有指出楼主代码的错因而已,因为楼主想知道他错在哪了。有点答非所问QAQ
by cute_overmind @ 2022-10-29 14:07:27
@WZRYWZWY 好的,下次注意