# Hỏi về cộng nhiều phân số

**URL:** https://daynhauhoc.com/t/hoi-ve-cong-nhieu-phan-so/110960
**Category:** programming
**Tags:** c++
**Created:** [December 20, 2020, 2:27am UTC](https://daynhauhoc.com/t/hoi-ve-cong-nhieu-phan-so/110960 "2020-12-20T02:27:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![manhphu](https://daynhauhoc.com/user_avatar/daynhauhoc.com/manhphu/32/56310_2.png) [@manhphu](https://daynhauhoc.com/u/manhphu)
#### Post date: [December 20, 2020, 2:27am UTC](https://daynhauhoc.com/t/hoi-ve-cong-nhieu-phan-so/110960/1 "2020-12-20T02:27:52Z")

</div>

ai giúp em cộng nhiều phân số với ạ

```auto
#include <stdio.h>
struct phanso
{
    int tu;
    int mau;
};

void nhapps(phanso a[], int &n)
{
    printf("n="); 
    scanf("%d",&n);
    for (int i = 0; i < n; i++)
    {
        printf("nhap tu:");
        scanf("%d", &a[i].tu);
        printf("nhap mau:");
        scanf("%d", &a[i].mau);
    }
}

void xuatps(phanso a[], int n)
{
    for (int i = 0; i < n; i++)
        printf("%d/%d\n", a[i].tu, a[i].mau);
}

void xuat1ps(phanso ps)
{
    printf("%d/%d\n", ps.tu, ps.mau);
}

int uscln(int a, int b)
{
    while (a != b)
    {
        if (a > b)
            a -= b;
        else
            b -= a;
    }
    return a;
}

phanso tongps(phanso a[], int n)
{
    int z;
    phanso tong;
    tong = a[1];
    for (int i = 1; i < n; i++)
    {
        tong.tu = tong.tu * a[i].mau + tong.mau * a[i].tu;
        tong.mau = tong.mau * a[i].mau;
        z = uscln(tong.tu, tong.mau);
        tong.tu /= z;
        tong.mau /= z;
        printf("tong cac phan so la:");
    }
    return tong;
}

int main()
{
    int n;
    phanso a[100];
    nhapps(a, n);
    xuatps(a, n);
    tongps(a,n);
}

```

---

<div class="post-metadata">

### Author: ![SITUVN.gcd](https://daynhauhoc.com/user_avatar/daynhauhoc.com/situvn.gcd/32/54493_2.png) [@SITUVN.gcd](https://daynhauhoc.com/u/SITUVN.gcd)
#### Post date: [December 20, 2020, 4:44am UTC](https://daynhauhoc.com/t/hoi-ve-cong-nhieu-phan-so/110960/2 "2020-12-20T04:44:45Z")

</div>

Nếu tính được tổng 2 phân số, thì tổng nhiều phân số chẳng khó gì. Vòng lặp + tổng 2 phân số = tổng nhiều phân số.
