我写了一个将小数转化成整数的代码,如下
#include<bits/stdc++.h>
using namespace std;
int f1(double x){
double xx = x;
while(xx-(int)(xx)>0){
cout<<"";
xx*=10;
}
xx/=10;
return xx;
}
int f2(double x){
int ans = 0;
double xx = x;
while(xx-(int)(xx)>0){
cout<<"";
xx*=10;
ans++;
}
xx/=10;
ans--;
return ans;
}
int main(){
double a, b;
cin>>a>>b;
printf("%d %d\n", f2(a), f2(b));
for(int i = 1; i <= max(f2(a), f2(b)); i++){
cout<<a<<" "<<b<<endl;
a*=10;
b*=10;
}
printf("%.0f %.0f", a, b);
return 0;
}
然后我输入
1.12
1.2
程序没有输出
这到底是什么情况