ios - 分数相加逻辑?
PHP中文网
PHP中文网 2017-04-17 17:47:35
0
2
473

1.要求求两个分数的和
2.要约分 要可以等于1 就不是要出现2/2 3/6
3.有没有公式啥的

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
巴扎黑

(๑乛◡乛๑)

a/b + c/d = (ad + bc) / (bd)

Appointment? Divide by the greatest common divisor

Peter_Zhu

Let me talk about my idea, although it may not be the optimal one.

A fraction is numerator/denominator. Therefore, a fraction is represented by two integers (mixed numbers are represented by improper fractions).

  1. The fractions are added up, which is a1/a2 + b1/b2 = (a1×b2+b1×a2)/(a2×b2). That is, the numerator of the sum is the numerator of the two fractions multiplied by the denominator of the other fraction and then added, and the denominator is the two denominators multiplied. Of course, this calculation may not be the simplest fraction, so we have to take the next step.

  2. Reduction is to find the greatest common divisor of the numerator and denominator of the sum, and then divide them by the greatest common divisor.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template