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

Commit

Permalink
162-207 completed
Browse files Browse the repository at this point in the history
  • Loading branch information
truonghoangkhiem committed Nov 3, 2023
1 parent dea4ccd commit f1a9988
Show file tree
Hide file tree
Showing 9 changed files with 502 additions and 6 deletions.
57 changes: 57 additions & 0 deletions 2. Bai162/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,65 @@
#include <iostream>
#include <iomanip>
using namespace std;

struct DaThuc
{
float a[100];
int n;
};
typedef struct DaThuc DATHUC;

void Nhap(DATHUC&);
void Xuat(DATHUC);

DATHUC Tich(DATHUC, DATHUC);

int main()
{
DATHUC f1;
cout << "Nhap da thuc f1:" << endl;
Nhap(f1);

DATHUC f2;
cout << "Nhap da thuc f2:" << endl;
Nhap(f2);

cout << "Tich da thuc: f1 * f2:" << endl;
Xuat(Tich(f1, f2));

return 0;
}

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

void Xuat(DATHUC f)
{
for (int i = f.n; i >= 1; i--)
{
cout << f.a[i];
cout << "x^" << i;
cout << setw(3);
}
cout << f.a[0];
}

DATHUC Tich(DATHUC f, DATHUC g)
{
DATHUC temp;
temp.n = f.n + g.n;
for (int i = temp.n; i >= 0; i--)
temp.a[i] = 0;
for (int i = 0; i <= g.n; i++)
for (int j = 0; j <= f.n; j++)
temp.a[i + j] += g.a[i] * f.a[j];
return temp;
}
41 changes: 41 additions & 0 deletions 2. Bai167/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,49 @@
#include <iostream>
#include <iomanip>
using namespace std;

struct DaThuc
{
float a[100];
int n;
};
typedef struct DaThuc DATHUC;

void Nhap(DATHUC&);
float VT(DATHUC, float);

int main()
{
DATHUC f1;
cout << "Nhap da thuc f1:" << endl;
Nhap(f1);

float x;
cout << "Nhap so thuc x:" << endl;
cin >> x;

cout << "x= "<<x<<" co gia tri la : " << VT(f1,x);

return 0;
}

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

float VT(DATHUC f, float x)
{
float s=0.0;
for (int i = 1; i <= f.n; i++)
f.a[i] = f.a[i] * pow(x, i);
for (int i = 0; i <= f.n; i++)
s += f.a[i];
return s;
}
64 changes: 63 additions & 1 deletion 2. Bai177/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,70 @@
#include <iostream>
using namespace std;

struct diem
{
float x;
float y;
};
typedef struct diem DIEM;

void Nhap(DIEM&);
void Nhap(DIEM[], int&);
void Xuat(DIEM);
float KhoangCachGoc(DIEM);
DIEM GanGocNhat(DIEM[], int);


int main()
{
DIEM a[100];
int n;
Nhap(a, n);

cout << "Diem gan goc toa do nhat la:";
Xuat(GanGocNhat(a, n));

return 0;
}
}

void Nhap(DIEM& P)
{
cout << "Nhap x: ";
cin >> P.x;
cout << "Nhap y: ";
cin >> P.y;
}

void Nhap(DIEM P[], int& n)
{
cout << "Nhap so luong diem: ";
cin >> n;
for (int i = 0; i <= n - 1; i++)
{
cout << "Nhap diem thu " << i << ": " << endl;
Nhap(P[i]);
}
}

void Xuat(DIEM P)
{
cout << "\nx: " << P.x;
cout << "\ny: " << P.y;
}



float KhoangCachGoc(DIEM P)
{
return sqrt(P.x * P.x + P.y * P.y);
}

DIEM GanGocNhat(DIEM a[], int n)
{
DIEM lc = a[0];
for (int i = 0; i <= n - 1; i++)
if (KhoangCachGoc(a[i]) <
KhoangCachGoc(lc))
lc = a[i];
return lc;
}
52 changes: 51 additions & 1 deletion 2. Bai182/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,58 @@
#include <iostream>
using namespace std;

int main()
struct PhanSo
{
int Tu;
int Mau;
};
typedef struct PhanSo PHANSO;

void Nhap(PHANSO&);
void Xuat(PHANSO);

void Nhap(PHANSO[], int&);
void Xuat(PHANSO[], int);

int main()
{
PHANSO P[100];
int n;
Nhap(P, n);
Xuat(P, n);
return 0;
}

void Nhap(PHANSO& P)
{
cout << "\nNhap Tu: ";
cin >> P.Tu;
cout << "Nhap Mau: ";
cin >> P.Mau;
}

void Xuat(PHANSO P)
{
cout << "\nTu: " << P.Tu;
cout << "\nMau: " << P.Mau;
}

void Nhap(PHANSO a[], int& n)
{
cout << "Nhap so luong phan so: ";
cin >> n;
for (int i = 0; i < n; i++)
{
cout << "\nNhap a[" << i << "] = ";
Nhap(a[i]);
}
}

void Xuat(PHANSO a[], int n)
{
for (int i = 0; i < n; i++)
{
cout << "\na[" << i << "] = ";
Xuat(a[i]);
}
}
59 changes: 57 additions & 2 deletions 2. Bai187/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,63 @@
#include <iostream>
using namespace std;

int main()
struct PhanSo
{
int Tu;
int Mau;
};
typedef struct PhanSo PHANSO;

void Nhap(PHANSO&);
void Xuat(PHANSO);

void Nhap(PHANSO[], int&);

PHANSO DuongDau(PHANSO[], int);

int main()
{
PHANSO P[100];
int n;
Nhap(P, n);
cout << "Duong dau tien trong mang la: ";
Xuat(DuongDau(P,n));
return 0;
}
}

void Nhap(PHANSO& P)
{
cout << "\nNhap Tu: ";
cin >> P.Tu;
cout << "Nhap Mau: ";
cin >> P.Mau;
}

void Xuat(PHANSO P)
{
cout << "\nTu: " << P.Tu;
cout << "\nMau: " << P.Mau;
}

void Nhap(PHANSO a[], int& n)
{
cout << "Nhap so luong phan so: ";
cin >> n;
for (int i = 0; i < n; i++)
{
cout << "\nNhap a[" << i << "] = ";
Nhap(a[i]);
}
}

PHANSO DuongDau(PHANSO a[], int n)
{
for (int i = 0; i < n; i++)
{
if (a[i].Tu * a[i].Mau > 0)
return a[i];
}
PHANSO temp{ 0,1 };
return temp;
}

34 changes: 34 additions & 0 deletions 2. Bai192/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
#include <iostream>
using namespace std;

struct SoPhuc
{
float Thuc;
float Ao;
};
typedef struct SoPhuc SOPHUC;

void Nhap(SOPHUC&);
void Nhap(SOPHUC[], int&);

int main()
{
SOPHUC a[100];
int n;
Nhap(a, n);

cout << "Da hoan thanh nhap mang mot chieu cac so phuc";

return 0;
}

void Nhap(SOPHUC& x)
{
cout << "Nhap thuc: ";
cin >> x.Thuc;
cout << "Nhap ao: ";
cin >> x.Ao;
}

void Nhap(SOPHUC a[], int& n)
{
cout << "Nhap n: ";
cin >> n;
for (int i = 0; i < n; i++)
{
cout << "Nhap a[" << i << "]: ";
Nhap(a[i]);
}
}
Loading

0 comments on commit f1a9988

Please sign in to comment.