wangrongsen1114 @ 2022-02-10 12:28:47
#include<iostream>
#include <iomanip>
using namespace std;
int main(){
int a,b,e=0,f=0;
double c=0,d=0,h=0,j=0;
cin>>a>>b;
for(int i=1;i<=a;i++){
if(i%b==0){
c+=i;
e++;
}
if(i%b!=0){
d+=i;
f++;
}
}
h=c/e;
j=d/f;
cout.unsetf(ios::fixed);
cout<<setprecision(3)<<h<<" "<<setprecision(3)<<j;
return 0;
by lucas_jy @ 2022-02-10 12:38:15
@wangrongsen1114
精确到小数点后
#include<iostream>
#include <iomanip>
using namespace std;
int main(){
int a,b,e=0,f=0;
double c=0,d=0,h=0,j=0;
cin>>a>>b;
for(int i=1;i<=a;i++){
if(i%b==0){
c+=i;
e++;
}
if(i%b!=0){
d+=i;
f++;
}
}
h=c/e;
j=d/f;
cout<<fixed<<setprecision(1)<<h<<" "<<setprecision(1)<<j;
return 0;
}
by wangrongsen1114 @ 2022-02-10 12:52:14
@lucas_jy 谢谢大佬 已关注