This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a30c34
commit 07b876a
Showing
13 changed files
with
919 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.