yezupei @ 2024-02-13 21:06:17
我总是出问题,b输出少一个0.1,哪位大神帮我一下,谢谢
by lelaimc @ 2024-02-17 16:16:51
能看下代码吗
by yezupei @ 2024-02-28 21:10:06
} @lelaimc 1.
using namespace std; int main() { int a,b,k,n,sum=0,ans=0; double p1,p2; cin>>n>>k; for(int i=1;i<=n;i++){ if(i%k==0){ a+=i; sum++;} else if(i%k!=0){ b+=i; ans++; } } p1=a1.0/sum; p2=b1.0/ans; cout<<fixed<<setprecision(1)<<p1<<endl; cout<<fixed<<setprecision(1)<<p2<<endl; return 0; }
by lelaimc @ 2024-02-29 22:08:12
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n,k;
double numa,numb,anda,andb;
cin>>n>>k;
for(int a=1;a<=n;a=a+1)
{
if(a%k==0)
{
numa=numa+1;
anda=anda+a;
}
else
{
numb=numb+1;
andb=andb+a;
}
}
printf("%.1lf",anda/numa);
cout<<" ";
printf("%.1lf",andb/numb);
return 0;
}
by lelaimc @ 2024-02-29 22:08:48
@yezupei 你看一下我的
by yezupei @ 2024-03-06 20:14:36
感谢