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

CodePudding user response:

reference _ boss reply: 3/f
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

Well, should be read from the file, the other all tried all wrong

CodePudding user response:

Kyrieup
reference 4 floor response:
Quote: refer to the third floor _ boss reply:
the general logic is above this, the for loop can use math repository, double pow (double x, double y) and the power function instead of to 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

Well, should be read from the file, the other all tried all wrong

Perform unexpected end of file doesn't have to be read from the file. Don't forget the standard input is also can input EOF. Linux is CTRL + d, under Windows is CTRL + z.

CodePudding user response:

reference _ boss reply: 3/f
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


Perform unexpected end of file doesn't have to be read from the file. Don't forget the standard input is also can input EOF. Linux is CTRL + d, under Windows is CTRL + z.

CodePudding user response:

Algorithm has a problem, decimal point 10000, more than double the accuracy of the
Use the LS code change

 int main () {
Int n, m, p;
Int I, k=0;
While (the scanf (" % d % d % d ", & amp; N, & amp; M, & amp; P)==3) {
N %=m;//take over, in order to calculate the decimal
For (I=0; I & lt; p; I++) {
N *=10;//like a subtraction borrow, borrow 10 times
K=n/m.//after a borrow and the dealer is the decimal number
N %=m;//continue to take over for a decimal
}
Printf (" % d \ n ", k);
}
return 0;
}

CodePudding user response:

The
reference 7 floor qybao response:
algorithm has a problem, the decimal point 10000, more than double precision
Use the LS code change

 int main () {
Int n, m, p;
Int I, k=0;
While (the scanf (" % d % d % d ", & amp; N, & amp; M, & amp; P)==3) {
N %=m;//take over, in order to calculate the decimal
For (I=0; I & lt; p; I++) {
N *=10;//like a subtraction borrow, borrow 10 times
K=n/m.//after a borrow and the dealer is the decimal number
N %=m;//continue to take over for a decimal
}
Printf (" % d \ n ", k);
}
return 0;
}

This algorithm is really smart, thank you very much (o ^ ^ o)
  • Related