黄戈 • 4个月前
会fmod直接用fmod,不会的自己写一个求小数除以小数的余数函数呗
fmod:
#include<bits/stdc++.h>
using namespace std;
int main (){
double a,b;
cin>>a>>b;
a=fmod(a,b);
cout<<setprecision(2)<<fixed<<a;
return 0;
}
自写fmod函数
#include<bits/stdc++.h>
using namespace std;
double f_mod(double a,double b){
double jl=b;
while(a>b){
b+=jl;
}
if(a==b){
return 0;
}
else{
b-=jl;
return a-b;
}
}
int main (){
double a,b,jl;
cin>>a>>b;
cout<<fixed<<setprecision(2)<<f_mod(a,b);
return 0;
}
评论: