Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
168 Done
Browse files Browse the repository at this point in the history
KevinNitroG committed Oct 26, 2023
1 parent af60db9 commit 1edf4f0
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions 2. Bai168/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,54 @@
#include <iostream>
using namespace std;
struct DaThuc
{
float a[100];
int n;
};
typedef struct DaThuc DATHUC;

void Nhap(DATHUC &);
void Xuat(DATHUC);
DATHUC operator+(DATHUC, DATHUC);

int main()
{
DATHUC P;
Nhap(P);

DATHUC Q;
Nhap(Q);

DATHUC R = P + Q;
Xuat(R);

return 0;
}

void Nhap(DaThuc &P)
{
cout << "Nhap bac da thuc: ";
cin >> P.n;
for (int i = 0; i <= P.n; i++)
{
cout << "Nhap he so a[" << i << "]: ";
cin >> P.a[i];
}
}

void Xuat(DATHUC P)
{
cout << "\nDa thuc: ";
for (int i = 0; i <= P.n; i++)
cout << P.a[i] << "x^" << i << " + ";
cout << "\b\b\b ";
}

DATHUC operator+(DATHUC P, DATHUC Q)
{
DATHUC temp;
temp.n = (P.n > Q.n) ? P.n : Q.n;
for (int i = 0; i <= temp.n; i++)
temp.a[i] = P.a[i] + Q.a[i];
return temp;
}

0 comments on commit 1edf4f0

Please sign in to comment.