Algorithm:
First, the integer part of the x/y is output, and the remaining number is u=x%y n times to meet the precision requirement.
Each test quotient: x=u*10 for dividend, y for divisor, quotient x/y (integer) as a result of a printout, the remainder is u=x%y. If you are not equal to 0, continue to test the business until u=0 or reach the N-position of the test operator.
Algorithm from: Yangkichang Editor, "computer programming typical examples of fine solutions" high-precision window, national Defense Science and Technology University Press published.
/* High Precision Division of two integer data */
#include <stdio.h>
int main ()
{
long int x,y,u,n;
printf ("Please enter two integers: \ n");
scanf ("%d%d", &x,&y);
printf ("You want to output several decimal points.") (If divisible, you only need to output a decimal point 0) \ n ");
scanf ("%d", &n);
printf ("Result: \ n");
printf ("%d/%d=\n%d.", x,y,x/y);
while (n--)
{
u=x%y;
x=u*10;
printf ("%d", x/y);
if (u==0)
Break
if (n%10==0)
printf ("\ n");
}
printf ("\ n");
return 0;
}