c语言 分数化小数

如题所述

#include "stdio.h"
#include "stdlib.h"
int main()
{
 int a,b,c;
 scanf("%d%d%d",&a,&b,&c);
 if(b==0 || c<0)
 {
  printf("Input error!Stop!\n");
  exit(0);
 }
 printf("%.*lf\n",c,a*1.0/b);
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-05-29
#include<stdio.h>
void main()
{
int a,b,c,d,i;
scanf("%d%d%d",&a,&b,&c);
d=a-a/b*b;
printf("%d.",a/b);
for(i=0;i<c;i++)
{
d=10*d;
printf("%d",d/b);
d=d-d/b*b;
}
printf("\n");
}
第2个回答  2017-08-04
#include<stdio.h>
int main()
{
long int a,b,c,n;
scanf("%d%d%d",&a,&b,&c);
printf("%d.",a/b);
while(c--)
{
n=a%b;
a=n*10;
printf("%d",a/b);
if(n==0)
break;
if(c==0)
printf("\n");
}
return 0;
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网