不知道数据范围,给你个参考

#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 );
}
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 );
}