我代码的想法是对一个数,先逐位输入,再反过来一个一个数位输出。
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
float m=0;
int a=0,b=0,c=0,d=0;
cin>>m;
a=m/100;
b=(m-100*a)/10;
c=m-100*a-10*b;
d=10*(m-100*a-10*b-c);
cout<<d<<"."<<c<<b<<a<<endl;
return 0;
}
然后试了几个数 发现当原数小数点后是1,3,6,8时输出的数首位分别是0,2,5,7 小数点后是其他数貌似是正确的,请问代码问题出在哪里,如何解决?谢谢!