Hướng dẫn sum of fractions in python - tổng các phân số trong python

Tôi đang cố gắng thêm hai phân số vào Python

Nếu đầu vào 1/4 + 1/4, tôi đang mong đợi 1/2 kết quả

Tôi đã xây dựng một lớp phân số với phương pháp __add__ để bổ sung

from fractions import gcd

class fraction:
    def __init__(self, numerator, denominator):
        self.num = numerator
        self.deno = denominator
    def __add__(self, other):
        self.sumOfn = self.num + other.num
        self.sumOfd = gcd(self.deno,other.deno)
        return(self.sumOfn, self.sumOfd)



print(fraction(1,4)+fraction(1,4))

Tuy nhiên, tôi nhận được 2,4 làm đầu ra, thực sự là 1/2, không đơn giản hóa. Làm thế nào tôi có thể khắc phục vấn đề đó?

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc
    Examples : 
     

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5

    Bàn luận 
     

    • Thêm hai phân số A/B và C/D và in câu trả lời ở dạng đơn giản nhất.examples: & nbsp; & nbsp;
    • Thuật toán để thêm hai phân số & nbsp; & nbsp;
    • Tìm một mẫu số chung bằng cách tìm LCM (nhiều điểm phổ biến nhất) của hai mẫu số.

    C++

    #include

    Thay đổi các phân số để có cùng một mẫu số và thêm cả hai điều khoản.

    Giảm phần cuối cùng thu được thành dạng đơn giản hơn bằng cách chia cả tử số và mẫu số cho yếu tố chung lớn nhất của chúng.

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    using namespace std;

    int gcd(int

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    1int
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    3

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    6
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    7

    1/500 + 2/1500 is equal to 1/300
    4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    8
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9
    1/500 + 2/1500 is equal to 1/300
    0

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9
    1/500 + 2/1500 is equal to 1/300
    3

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5__add__6

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5__add__8

    1/500 + 2/1500 is equal to 1/300
    4

    1/500 + 2/1500 is equal to 1/300
    5
    1/500 + 2/1500 is equal to 1/300
    6int
    1/500 + 2/1500 is equal to 1/300
    8int __add__0

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5int __add__4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5using7

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5using9

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5namespace1

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5namespace3

    1/500 + 2/1500 is equal to 1/300
    4

    1/500 + 2/1500 is equal to 1/300
    5 #include1int #include3int #include5int #include7

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    #include8int using0int using2int using4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5std;2

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5std;4std;5std;6std;7

    std;8std;9

    int namespace6

    1/500 + 2/1500 is equal to 1/300
    4

    Input: 1/2 + 3/2 Output: 2/1 Input: 1/3 + 3/9 Output: 2/3 Input: 1/5 + 3/15 Output: 2/55int std;0

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9 int2

    Java

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    int4 int5

    int gcd(int

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    1int
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    3

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    6
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    7

    1/500 + 2/1500 is equal to 1/300
    4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    8
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9
    1/500 + 2/1500 is equal to 1/300
    0

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9
    1/500 + 2/1500 is equal to 1/300
    3

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5__add__6

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5__add__8

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    22
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    23
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    24

    1/500 + 2/1500 is equal to 1/300
    4

    1/500 + 2/1500 is equal to 1/300
    5
    1/500 + 2/1500 is equal to 1/300
    6int
    1/500 + 2/1500 is equal to 1/300
    8int __add__0

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5int __add__4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    1/500 + 2/1500 is equal to 1/300
    5 #include1int #include3int #include5int #include7

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5using9

    #include8int using0int using2int using4

    int namespace6

    1/500 + 2/1500 is equal to 1/300
    4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5int std;0

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9 int2

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    67
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    23
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    69
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    70
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    71
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    23
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    73
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    74
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    75

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    77

    1/500 + 2/1500 is equal to 1/300
    4

    1/500 + 2/1500 is equal to 1/300
    4

    Python3

    Java

    int4 int5

    int gcd(int

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    1int
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    3

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    6
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    7

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    8
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9
    1/500 + 2/1500 is equal to 1/300
    0

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9
    1/500 + 2/1500 is equal to 1/300
    3

    1/500 + 2/1500 is equal to 1/300
    5
    1/500 + 2/1500 is equal to 1/300
    6int
    1/500 + 2/1500 is equal to 1/300
    8int __add__0

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5int __add__4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    1/500 + 2/1500 is equal to 1/300
    18
    1/500 + 2/1500 is equal to 1/300
    19
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    23
    1/500 + 2/1500 is equal to 1/300
    21

    1/500 + 2/1500 is equal to 1/300
    5 #include1int #include3int #include5int #include7

    #include8int using0int using2int using4

    int namespace6

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5int std;0

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9 int2

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    1/500 + 2/1500 is equal to 1/300
    52

    Java

    int4 int5

    1/500 + 2/1500 is equal to 1/300
    18
    1/500 + 2/1500 is equal to 1/300
    68
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    23
    1/500 + 2/1500 is equal to 1/300
    70
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    70
    1/500 + 2/1500 is equal to 1/300
    72
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    23
    1/500 + 2/1500 is equal to 1/300
    74

    int6 int gcd(int

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    1int
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    3

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    77

    C#

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9 int2

    Java

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    using namespace std;

    int gcd(int

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    1int
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    3

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    6
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    7

    1/500 + 2/1500 is equal to 1/300
    4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    8
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9
    1/500 + 2/1500 is equal to 1/300
    0

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9
    1/500 + 2/1500 is equal to 1/300
    3

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5__add__6

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5__add__8

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5__add__18
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    23
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    24

    1/500 + 2/1500 is equal to 1/300
    4

    1/500 + 2/1500 is equal to 1/300
    5
    1/500 + 2/1500 is equal to 1/300
    6int
    1/500 + 2/1500 is equal to 1/300
    8int __add__0

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    1/500 + 2/1500 is equal to 1/300
    5 #include1int #include3int #include5int #include7

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5using9

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5int namespace1

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5namespace3

    1/500 + 2/1500 is equal to 1/300
    4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    50 int6
    1/500 + 2/1500 is equal to 1/300
    5 __add__48

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5int __add__52

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5__add__54
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    23
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    69
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    70
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    71
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    23
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    73
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    74
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    75

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    77

    1/500 + 2/1500 is equal to 1/300
    4

    1/500 + 2/1500 is equal to 1/300
    4

    PHP

    __add__67

    __add__68 gcd(__add__70__add__71__add__72gcd(8

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    6 std;5__add__70 __add__79

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    8
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9 __add__72
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    65

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9 gcd(__add__72 __add__88__add__70__add__71__add__70
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    75

    1/500 + 2/1500 is equal to 1/300
    4

    __add__68 __add__95__add__96__add__97__add__98gcd(8

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5#include02 #include03__add__98__add__71__add__96
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    75

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5__add__96 #include10__add__96 #include12#include02
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    65

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5__add__98 #include17__add__98 #include12#include02
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    65

    1/500 + 2/1500 is equal to 1/300
    4

    __add__68 #include1#include25__add__71#include27__add__71#include29

    1/500 + 2/1500 is equal to 1/300
    74

    #include31#include32__add__97__add__98__add__97__add__96__

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    4

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5__add__96 #include03#include27__add__71#include32
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    75

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5__add__96 #include48#include27 #include50#include32#include522__add__96
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    65

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5__add__98 #include48#include25#include59__add__96 #include12#include27#include63

    1/500 + 2/1500 is equal to 1/300
    45std;5#include29#include59__add__96 #include12______432

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    1/500 + 2/1500 is equal to 1/300
    6__add__96__add__71__add__98
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    75

    1/500 + 2/1500 is equal to 1/300
    4

    #include25 #include80#include27 #include82

    #include29 #include84#include32 #include86

    __add__96#include88__add__98

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    65

    #include1#include25__add__71#include27__add__71#include29

    1/500 + 2/1500 is equal to 1/300
    74

    1/500 + 2/1500 is equal to 1/300
    45#include32__add__71__add__98__add__71__add__96
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    75

    using05 #include25__add__71

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    23__add__71#include27____371
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    70
    1/500 + 2/1500 is equal to 1/300
    74

    using14#include29

    1/500 + 2/1500 is equal to 1/300
    74
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    23__add__71#include32__add__71
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    74
    1/500 + 2/1500 is equal to 1/300
    74

    using23__add__98__add__71

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    23__add__71__add__96__add__71using30
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    65

    using32

    JavaScript

    using33

    using34

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    6
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    7

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    8
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9
    1/500 + 2/1500 is equal to 1/300
    0

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    9 using43

    1/500 + 2/1500 is equal to 1/300
    4

    using45

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5using47

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5using49

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5using51

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5using53

    1/500 + 2/1500 is equal to 1/300
    4

    using55

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5using57

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5using59

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5using61

    1/500 + 2/1500 is equal to 1/300
    45using63

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    5
    1/500 + 2/1500 is equal to 1/300
    52

    1/500 + 2/1500 is equal to 1/300
    4

    using67

    using68

    using69

    using70

    using71

    Input:  1/2 + 3/2
    Output: 2/1
    
    Input:  1/3 + 3/9
    Output: 2/3
    
    Input:  1/5 + 3/15
    Output: 2/5
    77

    using73

    Đầu ra: & nbsp; 

    1/500 + 2/1500 is equal to 1/300

    Độ phức tạp về thời gian: O (log (min (a, b)), trong đó a và b là hai số nguyên. O(log(min(a, b)), where a and b are two integers.

    Không gian phụ trợ: O (1), không cần thêm không gian để nó là một hằng số. O(1), no extra space required so it is a constant.

    Xem bên dưới để thực hiện tương tự bằng cách sử dụng các chức năng thư viện. & NBSP; thao tác tỷ lệ trong C ++ | Đặt 1 (Số học) & NBSP; Bài viết này được đóng góp bởi Rahul Agrawal. Nếu bạn thích GeekSforGeeks và muốn đóng góp, bạn cũng có thể viết một bài viết bằng Write.GeeksForGeek.org hoặc gửi bài viết của bạn. Xem bài viết của bạn xuất hiện trên trang chính của GeekSforGeek và giúp các chuyên viên máy tính khác. Xin vui lòng viết nhận xét nếu bạn tìm thấy bất cứ điều gì không chính xác hoặc bạn muốn chia sẻ thêm thông tin về chủ đề được thảo luận ở trên. & NBSP;
    Ratio Manipulations in C++ | Set 1 (Arithmetic) 
    This article is contributed by Rahul Agrawal .If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.
    Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
     


    Bỏ phiếu cho khó khăn

    Khó khăn hiện tại: Dễ dàng

    Làm thế nào để bạn tìm thấy tổng của các phân số?

    Kiểm tra mẫu số của các phân số.Làm cho các mẫu số của các phân số giống nhau, bằng cách tìm thấy LCM của mẫu số và hợp lý hóa chúng.Thêm các tử số của các phân số, giữ cho mẫu số phổ biến.Đơn giản hóa phân số để có được tổng cuối cùng.

    Bạn có thể làm phân số trong Python không?

    Từ Python 3.2 trở đi, bạn cũng có thể xây dựng một thể hiện phân số trực tiếp từ một số thập phân.Ví dụ thập phân.you can also construct a Fraction instance directly from a decimal. Decimal instance.