High-Precision decimal,

Source: Internet
Author: User

High-Precision decimal,

Subject content:

Due to the limitation of the internal expression of the computer, there are Precision Problems in floating point operations. To obtain high-precision computing results, you need to design your own implementation method.

Any floating point number between (0, 1) can be expressed as the quotient of two positive integers. To express the quotient of the two numbers, the result of division can be expressed as multiple integers, each integer represents one digit of the result. That is to say, the first digit of the quotient is represented by an integer, the second digit is represented by another integer, and so on, a high precision division result can be output.

For example, if the result of 16/19 is 0. 8421052631..., 8, 4, 2, 1, 0, 5, 2, 6, 3, and 1 are output in sequence ....

The process of division can be used to simulate the method of dividing by vertical manually columns. Multiply the devisor by 10 first. After obtaining a quotient, multiply the remainder by 10 as the devisor for the next round of calculation:

160/19-> 8 + 8

80/19-> 4 + 4

...

When the remainder is 0, the remainder is exhausted.

Now, write a program, enter a score, and calculate its decimal form. Whether or not the decimal point can be exceeded, the output can be up to 200 digits after the decimal point.

 

Input Format:

Shape

A/B

10 <= a <B <100. That is to say, the decimal point must be a positive number smaller than 1.

 

Tip: the input contains "/" in the middle of two numbers. Therefore, scanf should adopt the input format "% d/% d.

 

Output Format:

Shape

0. xxxxxxxxx

Decimal point, which can be up to 200 digits after the decimal point. When the output ends, wrap the line with a carriage return. If a/B is a finite, non-repeating decimal number, all the valid bits are output. You do not need to output the following 0 to fill the 200 BITs.

 

 

# Include <stdio. h>
Int main ()
{
Int n, m, c = 0;
Scanf ("% d/% d", & n, & m );
Printf ("0 .");
While (c <200 ){
C ++;
N * = 10;
Printf ("% d", n/m );
N % = m;
If (n = 0)
Break;
}

Return 0;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.