两数相除
Description输入两个正整数,a和b,求出a/b的结果中小数点后的20位。
Input
Output
注意行尾输出回车。
注意最后一位数字的四舍五入。
Sample Input
5 3
Sample Output
66666666666666666667
这题怎么做啊,帮帮忙啊
程序代码:#include <cstdio>
void foo( unsigned a, unsigned b )
{
char buf[21];
a=a%b;
for( size_t i=0; i!=21; ++i, a=(a*10)%b )
buf[i] = (a*10)/b;
unsigned carry = buf[20]>=5;
buf[20] = '\0';
for( size_t i=0; i!=20; ++i )
{
carry += buf[19-i];
buf[19-i] = carry%10 + '0';
carry /= 10;
}
puts( buf );
}
int main( void )
{
foo( 5, 3 );
foo( 97, 89 );
}