小数化分数
/*小数化分数,非循环*/#include<stdio.h>
#include<ctype.h>
#include<math.h>
double zdgys(double c,double d)
{double o,p;
o=1;p=1;
while(c/o!=d/p)
{while(c/o>d/p)
o++;
while(c/o<d/p)
p++;
}
while(c/o==d/p)
return (c/o);
}
main()
{ double m,im,j=1;
int l;
/* clrscr(); */
printf("Input decimal fraction:\n");
scanf("%f",&m);
im=floor(m);
while(m!=im)
{m*=10;
j*=10;
im=floor(m);
}
l=zdgys(m,j);
m=m/l;
j=j/l;
printf("The fenshu is %f,%f",m,j);
}