include <stdio.h>void main(){float k=0,n;scanf("%f",&n);while(n!=(int)n){n*=10;k++;}while(k){n=(int)(n+5)/10;k--;}printf("%.f",n);}运行示例:
int main(){ int a,b,k;printf("请输入分子分母和百分比的小数位数:\n");scanf("%d%d%d",&a,&b,&k);printf("%d/%d=%.*f%%\n",a,b,k,a*100.0/b);return 0;}