Home > Back-end > Elder people save the children! Thank you very much!
Elder people save the children! Thank you very much!
Time:10-23
7-5 two senior god operator (10) Two senior has retired jianghu for many years, there's no one knows what does she look like, but in those days wandering senior one second in legend, is still the subject of speculation, according to legend yu yu senior operator is a god, as long as give her three integers, n, p, m, she can tell you in a second n by m behind the decimal point of the first p is how much, no matter you believe it or not, anyway I have believed,
Input format: Have multiple sets of test data, perform unexpected end of file, each group of test data, there are three integers, n, m, p (0 & lt; N & lt; 10, 0 & lt; M & lt; 10 ^ 7, 0 & lt; P & lt; 10 ^ 5),
The output format: For each group of input, n/m in the first p decimal places, each output a line,
Input the sample: Given a set of input here, for example:
1 2 3 2 4 1
The output sample: Here is given the corresponding output, for example:
0 5
CodePudding user response:
First to float the output=(float) n/m into a floating point number, Access to the first decimal (output 10 * 10) % Access to 2 decimal places (the output * 10-100) % Other similar
CodePudding user response:
# include & lt; stdio.h>
Int main (void) { Int n, m, p; int i; Double output;
While (the scanf (" % d % d % d ", & amp; N, & amp; M, & amp; P)==3) { The output=n * 1.0/m;
For (I=0; I & lt; p; I++) The output *=10;
Printf (" % d \ n ", (int), the output % 10); }
return 0; }
For your reference ~
CodePudding user response:
The general logic is above this, the for loop can use math repository (double x, double y) for double pow to the power function, to go to is rigorous, the range of the input value restrictions have to write a prompt, input format said, "how much test data set, the implementation of the file at the end", don't know is to write an array once receive more groups of input, or read the input data in a text file, there are corresponding to a set of fixed writing