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

Commit

Permalink
178 - 238 Done
Browse files Browse the repository at this point in the history
  • Loading branch information
MinhHuy1507 committed Oct 24, 2023
1 parent 2a30c34 commit 07b876a
Show file tree
Hide file tree
Showing 13 changed files with 919 additions and 12 deletions.
18 changes: 9 additions & 9 deletions 2. Bai178/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <iostream>
#include <cmath>
using namespace std;

struct Diem
Expand All @@ -8,15 +9,14 @@ struct Diem
};
typedef struct Diem DIEM;

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

void Xuat(DIEM);
void Xuat(DIEM[], int);


float KhoangCach(DIEM, DIEM);
void GanNhauNhat(DIEM[], int,DIEM&,DIEM&);
void GanNhauNhat(DIEM[], int, DIEM &, DIEM &);

int main()
{
Expand All @@ -29,15 +29,15 @@ int main()
return 0;
}

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

void Nhap(DIEM a[], int& n)
void Nhap(DIEM a[], int &n)
{
cout << "Nhap n: ";
cin >> n;
Expand Down Expand Up @@ -67,12 +67,12 @@ float KhoangCach(DIEM P, DIEM Q)
return sqrt((P.x - Q.x) * (P.x - Q.x) + (P.y - Q.y) * (P.y - Q.y));
}

void GanNhauNhat(DIEM a[], int n,DIEM& P, DIEM& Q)
void GanNhauNhat(DIEM a[], int n, DIEM &P, DIEM &Q)
{
P = a[0];
Q = a[1];
for(int i=0;i<n;i++)
for(int j=i+1;j<n-1;j++)
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n - 1; j++)
if (KhoangCach(a[i], a[j]) < KhoangCach(P, Q))
{
P = a[i];
Expand Down
52 changes: 51 additions & 1 deletion 2. Bai183/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]);
}
}
94 changes: 94 additions & 0 deletions 2. Bai188/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,102 @@
#include <iostream>
using namespace std;

struct PhanSo
{
int Tu;
int Mau;
};
typedef struct PhanSo PHANSO;

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

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

PHANSO DuongDau(PHANSO[], int);
int SoSanh(PHANSO, PHANSO);
PHANSO DuongNhoNhat(PHANSO[], int);

int main()
{
PHANSO P[100];
int n;
Nhap(P, n);
cout << "Duong nho nhat: ";
PHANSO temp = DuongNhoNhat(P, n);
Xuat(temp);
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]);
}
}

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{ -1,1 };
return temp;
}

int SoSanh(PHANSO x, PHANSO y)
{
float a = (float)x.Tu / x.Mau;
float b = (float)y.Tu / y.Mau;
if (a > b)
return 1;
if (a < b)
return -1;
return 0;
}

PHANSO DuongNhoNhat(PHANSO a[], int n)
{
if (n == 0)
{
PHANSO lc = { -1, 1 };
return lc;
}
PHANSO lc = DuongDau(a, n);
for (int i = 0; i < n - 1; i++)
{
if (SoSanh(a[i], lc) == -1 && a[i].Tu * a[i].Mau > 0)
lc = a[i];
}
return lc;
}
64 changes: 64 additions & 0 deletions 2. Bai193/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,72 @@
#include <iostream>
using namespace std;

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

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

void Xuat(SOPHUC);

SOPHUC Tong(SOPHUC, SOPHUC);
SOPHUC Tong(SOPHUC[], int);

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

cout << "Tong cua cac so phuc: ";
Xuat(Tong(a, n));

return 0;
}

void Nhap(SOPHUC& x)
{
cout << "\nNhap 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]);
}
}

void Xuat(SOPHUC x)
{
cout << "\nThuc = " << x.Thuc;
cout << "\nAo = " << x.Ao;
}

SOPHUC Tong(SOPHUC x, SOPHUC y)
{
SOPHUC temp{};
temp.Thuc = x.Thuc + y.Thuc;
temp.Ao = x.Ao + y.Ao;
return temp;
}

SOPHUC Tong(SOPHUC a[], int n)
{
SOPHUC s = { 0,0 };
for (int i = 0; i < n; i++)
{
s = Tong(s, a[i]);
}
return s;
}
90 changes: 90 additions & 0 deletions 2. Bai198/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,98 @@
#include <iostream>
#include <cmath>
using namespace std;

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

struct DuongTron
{
DIEM I;
float R;
};
typedef struct DuongTron DUONGTRON;

void Nhap(DIEM&);
void Nhap(DUONGTRON&);
void Nhap(DUONGTRON[], int&);

void Xuat(DIEM);
void Xuat(DUONGTRON);

float KhoangCach(DIEM);
float KhoangCachGoc(DUONGTRON);
DUONGTRON GanGocNhat(DUONGTRON a[], int n);

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

cout << "\nDuong tron gan goc toa do nhat: \n";
Xuat(GanGocNhat(a, n));
return 0;
}

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

void Nhap(DUONGTRON& c)
{
cout << "\nNhap tam I: ";
Nhap(c.I);
cout << "\nNhap R: ";
cin >> c.R;
}

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

void Xuat(DIEM I)
{
cout << "(" << I.x << ", " << I.y << ")";
}

void Xuat(DUONGTRON c)
{
cout << "\nI = ";
Xuat(c.I);
cout << "R = " << c.R;
}

float KhoangCach(DIEM I)
{
return sqrt(I.x * I.x + I.y * I.y);
}

float KhoangCachGoc(DUONGTRON c)
{
float kc = KhoangCach(c.I);
return abs(kc - c.R);
}

DUONGTRON GanGocNhat(DUONGTRON a[], int n)
{
DUONGTRON lc = a[0];
for (int i = 0; i < n; i++)
if (KhoangCachGoc(lc) > KhoangCachGoc(a[i]))
lc = a[i];
return lc;
}
Loading

0 comments on commit 07b876a

Please sign in to comment.