Topic content:
Because of the limitation of the internal expression of the computer, the floating-point arithmetic has the precision problem, in order to obtain the high precision computation result, must design the realization method.
Any floating-point number between (0,1) can be expressed as a quotient of two positive integers, in order to express the quotient of such two numbers, the result of division can be represented by multiple integers, and each integer represents one of the results. The first digit of the quotient is represented by an integer, the second is represented by another integer, and so on, a high-precision division result can be output.
Results such as 16/19 of 0.8421052631 ... You can sequentially output 8, 4, 2, 1, 0, 5, 2, 6, 3, 1 ....
And the division of the process, you can imitate the manual column to do division, the divisor is multiplied by 10, after a quotient, the remainder is multiplied by 10 as the next round of calculation dividend:
160/19->8 Yu 8
80/19->4 Yu 4
...
When the remainder is 0 o'clock, the exception is shown.
Now, write a program, enter a fraction, and calculate its decimal form. Outputs up to 200 digits after the decimal point, whether or not it can be removed.
Input format:
Shaped like
A/b
Two numbers, of which 10<=a<b<100. In other words, the decimal number must be a positive number less than 1.
Output format:
Shaped like
0.xxxxxxxxx
Decimal, up to 200 digits after the decimal point. The output ends with a carriage return with a newline. If A/b is a limited non-repeating decimal, then the output of all the valid bits will be able to, do not need to output the back of the 200-bit full.
Input Sample:
16/19
Sample output:
0.84210526315789473684210526315789473684210526315789473684210526315789473684210526315789473684210526315789473684210526315 789473684210526315789473684210526315789473684210526315789473684210526315789473684
time limit: 500ms memory limit: 32000kb
#include <stdio.h>intMain () {intA, B; intx; intn=0; scanf ("%d/%d",&a,&b); printf ("0."); while(n< $) {a= A *Ten; X= A/b; printf ("%d", x); A= a%b; N++; if(A = =0){ Break; } } return 0;}
Calculate the exact value of a score Onge Teacher C Language Programming cap 8th Chapter programming problem