#include <iostream>
using namespace std;
int main() {
int a, b, N;
while ( cin >> a >> b >> N ) {
cout << a / b << ".";
a %= b;
while ( N-- ) {
a *= 10;
cout << a / b;
a %= b;
}
cout << endl;
}
return 0;
}
可以再簡潔
#include <iostream>
using namespace std;
int main()
{
int a,b;
unsigned short N;
while(cin>>a>>b>>N)
{
cout<<a/b<<".";
while(N--)
{
a=a%b*10;
cout<<a/b;
}
cout<<endl;
}
}