#include <stdio.h>
int main(){
int a,b,c,pow,mod,n;
while(scanf("%d%d%d",&a,&b,&c)==3){
printf("a=%d b=%d c=%d\n",a,b,c);
n=a/b;
printf("%d",n);
if(c>0&&c<=100){
printf(".");
pow=10;
while(c--){
mod=(a*pow/b)%10;
printf("%d",mod);
pow*=10;
}
}
}
return 0;
}
上面的版本没有进行4舍5入,下面是进行了4舍5入的版本
#include <stdio.h>
int main(){
int a,b,c,pow,mod,n;
while(scanf("%d%d%d",&a,&b,&c)==3){
printf("a=%d b=%d c=%d\n",a,b,c);
n=a/b;
printf("%d",n);
if(c>0&&c<=100){
printf(".");
pow=10;
while(c--){
mod=(a*pow/b)%10;
if(c!=0){
printf("%d",mod);
pow*=10;
}else if((a*10*pow/b)%10>=5){
mod++;
printf("%d",mod);
}else{
printf("%d",mod);
}
}
}
}
return 0;
}