From 58c8da060d2e26f668e34a4ce0203f7183864ac0 Mon Sep 17 00:00:00 2001 From: KevinNitroG Date: Mon, 13 Nov 2023 18:31:52 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5=20(Bai=20196=20=E2=86=92=20231):?= =?UTF-8?q?=20Done?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bai196/Source.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++- Bai201/Source.cpp | 37 ++++++++++++++++++++++++++++++++++- Bai206/Source.cpp | 42 ++++++++++++++++++++++++++++++++++++++++ Bai211/Source.cpp | 32 +++++++++++++++++++++++++++++++ Bai216/Source.cpp | 34 ++++++++++++++++++++++++++++++++ Bai221/Source.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++ Bai226/Source.cpp | 32 +++++++++++++++++++++++++++++++ Bai231/Source.cpp | 37 +++++++++++++++++++++++++++++++++++ 8 files changed, 306 insertions(+), 2 deletions(-) diff --git a/Bai196/Source.cpp b/Bai196/Source.cpp index 9e1927f..65866d9 100644 --- a/Bai196/Source.cpp +++ b/Bai196/Source.cpp @@ -1,8 +1,55 @@ #include +#include using namespace std; +void Nhap(int[][100], int &, int &); +int ktToanChan(int); +void LietKe(int[][100], int, int); + int main() { + int m, n, a[100][100]; + Nhap(a, m, n); + cout << "Day so cac so nguyen toan chan la:" << endl; + LietKe(a, m, n); + return 0; +} + +void Nhap(int a[][100], int &m, int &n) +{ + cout << "Nhap so dong: "; + cin >> m; + cout << "Nhap so cot: "; + cin >> n; + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) + { + cout << "Nhap a[" << i << "][" << j << "]: "; + cin >> a[i][j]; + } +} +int ktToanChan(int n) +{ + n = abs(n); + if (n <= 9) + { + if (n % 2 == 0) + return 1; + return 0; + } + int dv = n % 10; + if (ktToanChan(n / 10) == 1 && dv % 2 == 0) + return 1; return 0; -} \ No newline at end of file +} + +void LietKe(int a[][100], int m, int n) +{ + if (m == 0) + return; + LietKe(a, m - 1, n); + for (int j = 0; j < n; j++) + if (ktToanChan(a[m - 1][j])) + cout << setw(4) << a[m - 1][j]; +} diff --git a/Bai201/Source.cpp b/Bai201/Source.cpp index 9e1927f..7fa4d67 100644 --- a/Bai201/Source.cpp +++ b/Bai201/Source.cpp @@ -1,8 +1,43 @@ #include +#include using namespace std; +void Nhap(int[][100], int &, int &); +void LietKe(int[][100], int, int); + int main() { + int m, n, a[100][100]; + Nhap(a, m, n); + + int k; + cout << "Nhap cot k can liet ke: "; + cin >> k; + cout << "Day so cac so chan tren cot " << k << " la:" << endl; + LietKe(a, m, k); return 0; -} \ No newline at end of file +} + +void Nhap(int a[][100], int &m, int &n) +{ + cout << "Nhap so dong: "; + cin >> m; + cout << "Nhap so cot: "; + cin >> n; + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) + { + cout << "Nhap a[" << i << "][" << j << "]: "; + cin >> a[i][j]; + } +} + +void LietKe(int a[][100], int m, int k) +{ + if (m == 0) + return; + LietKe(a, m - 1, k); + if (a[m - 1][k] % 2 == 0) + cout << setw(4) << a[m - 1][k]; +} diff --git a/Bai206/Source.cpp b/Bai206/Source.cpp index 9e1927f..02eb2c2 100644 --- a/Bai206/Source.cpp +++ b/Bai206/Source.cpp @@ -1,8 +1,50 @@ #include using namespace std; +void Nhap(int[][100], int &, int &); +bool ktChinhPhuong(int); +int TongChinhPhuong(int[][100], int, int); + int main() { + int m, n, a[100][100]; + Nhap(a, m, n); + cout << "Tong so chinh phuong tren cac cot co chi so le la:" << TongChinhPhuong(a, m, n) << endl; return 0; +} + +void Nhap(int a[][100], int &m, int &n) +{ + cout << "Nhap so dong: "; + cin >> m; + cout << "Nhap so cot: "; + cin >> n; + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) + { + cout << "Nhap a[" << i << "][" << j << "]: "; + cin >> a[i][j]; + } +} + +bool ktChinhPhuong(int n) +{ + if (n < 1) + return false; + for (int i = 1; i * i <= n; i++) + if (i * i == n) + return true; + return false; +} + +int TongChinhPhuong(int a[][100], int m, int n) +{ + if (m == 0) + return 0; + int s = TongChinhPhuong(a, m - 1, n); + for (int j = 0; j < n; j++) + if (ktChinhPhuong(a[m - 1][j]) && j % 2 != 0) + s = s + a[m - 1][j]; + return s; } \ No newline at end of file diff --git a/Bai211/Source.cpp b/Bai211/Source.cpp index 9e1927f..d10894f 100644 --- a/Bai211/Source.cpp +++ b/Bai211/Source.cpp @@ -1,8 +1,40 @@ #include using namespace std; +void Nhap(float[][100], int &, int &); +float TongAm(float[][100], int, int); + int main() { + float a[100][100]; + int m, n; + Nhap(a, m, n); + cout << "Tong cac so am trong ma tran: " << TongAm(a, m, n) << endl; return 0; +} + +void Nhap(float a[][100], int &m, int &n) +{ + cout << "Nhap so dong: "; + cin >> m; + cout << "Nhap so cot: "; + cin >> n; + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) + { + cout << "Nhap a[" << i << "][" << j << "]: "; + cin >> a[i][j]; + } +} + +float TongAm(float a[][100], int m, int n) +{ + if (m == 0) + return 0; + float s = TongAm(a, m - 1, n); + for (int j = 0; j < n; j++) + if (a[m - 1][j] < 0) + s = s + a[m - 1][j]; + return s; } \ No newline at end of file diff --git a/Bai216/Source.cpp b/Bai216/Source.cpp index 9e1927f..d9a7e50 100644 --- a/Bai216/Source.cpp +++ b/Bai216/Source.cpp @@ -1,8 +1,42 @@ #include using namespace std; +void Nhap(float[][100], int &, int &); +float TongDong(float[][100], int, int); + int main() { + float a[100][100]; + int m, n; + Nhap(a, m, n); + + int k; + cout << "Nhap cot k: "; + cin >> k; + cout << "Tong gia tri tren dong " << k << " la:" << TongDong(a, n, k) << endl; return 0; +} + +void Nhap(float a[][100], int &m, int &n) +{ + cout << "Nhap so dong: "; + cin >> m; + cout << "Nhap so cot: "; + cin >> n; + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) + { + cout << "Nhap a[" << i << "][" << j << "]: "; + cin >> a[i][j]; + } +} + +float TongDong(float a[][100], int n, int d) +{ + if (n == 0) + return 0; + float s = TongDong(a, n - 1, d); + s = s + a[d][n - 1]; + return s; } \ No newline at end of file diff --git a/Bai221/Source.cpp b/Bai221/Source.cpp index 9e1927f..bc044d7 100644 --- a/Bai221/Source.cpp +++ b/Bai221/Source.cpp @@ -1,8 +1,53 @@ #include using namespace std; +void Nhap(int[][100], int &, int &); +bool ktChinhPhuong(int); +int TongCot(int[][100], int, int); + int main() { + int m, n, a[100][100]; + Nhap(a, m, n); + + int k; + cout << "Nhap cot k: "; + cin >> k; + cout << "Tong so chinh phuong tren cot " << k << " la:" << TongCot(a, m, k) << endl; return 0; +} + +void Nhap(int a[][100], int &m, int &n) +{ + cout << "Nhap so dong: "; + cin >> m; + cout << "Nhap so cot: "; + cin >> n; + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) + { + cout << "Nhap a[" << i << "][" << j << "]: "; + cin >> a[i][j]; + } +} + +bool ktChinhPhuong(int n) +{ + if (n < 1) + return false; + for (int i = 1; i * i <= n; ++i) + if (i * i == n) + return true; + return false; +} + +int TongCot(int a[][100], int m, int c) +{ + if (m == 0) + return 0; + int s = TongCot(a, m - 1, c); + if (ktChinhPhuong(a[m - 1][c])) + s = s + a[m - 1][c]; + return s; } \ No newline at end of file diff --git a/Bai226/Source.cpp b/Bai226/Source.cpp index 9e1927f..67d2570 100644 --- a/Bai226/Source.cpp +++ b/Bai226/Source.cpp @@ -1,8 +1,40 @@ #include using namespace std; +void Nhap(float[][100], int &, int &); +int DemDuong(float[][100], int, int); + int main() { + int m, n; + float a[100][100]; + Nhap(a, m, n); + cout << "So luong so duong trong ma tran: " << DemDuong(a, m, n) << endl; return 0; +} + +void Nhap(float a[][100], int &m, int &n) +{ + cout << "Nhap so dong: "; + cin >> m; + cout << "Nhap so cot: "; + cin >> n; + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) + { + cout << "Nhap a[" << i << "][" << j << "]: "; + cin >> a[i][j]; + } +} + +int DemDuong(float a[][100], int m, int n) +{ + if (m == 0) + return 0; + int dem = DemDuong(a, m - 1, n); + for (int j = 0; j < n; j++) + if (a[m - 1][j] > 0) + dem = dem + 1; + return dem; } \ No newline at end of file diff --git a/Bai231/Source.cpp b/Bai231/Source.cpp index 9e1927f..03493cc 100644 --- a/Bai231/Source.cpp +++ b/Bai231/Source.cpp @@ -1,8 +1,45 @@ #include using namespace std; +void Nhap(float[][100], int &, int &); +int TanSuat(float[][100], int, int, float); + int main() { + int m, n; + float a[100][100]; + Nhap(a, m, n); + + float x; + cout << "Nhap so x:"; + cin >> x; + + cout << "So lan xuat hien cua " << x << " trong ma tran: " << TanSuat(a, m, n, x) << endl; return 0; +} + +void Nhap(float a[][100], int &m, int &n) +{ + cout << "Nhap so dong: "; + cin >> m; + cout << "Nhap so cot: "; + cin >> n; + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) + { + cout << "Nhap a[" << i << "][" << j << "]: "; + cin >> a[i][j]; + } +} + +int TanSuat(float a[][100], int m, int n, float x) +{ + if (m == 0) + return 0; + int dem = TanSuat(a, m - 1, n, x); + for (int j = 0; j < n; j++) + if (a[m - 1][j] == x) + dem = dem + 1; + return dem; } \ No newline at end of file