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
59cfd85
commit 58c8da0
Showing
8 changed files
with
306 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,55 @@ | ||
#include <iostream> | ||
#include <iomanip> | ||
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; | ||
} | ||
} | ||
|
||
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]; | ||
} |
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,43 @@ | ||
#include <iostream> | ||
#include <iomanip> | ||
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; | ||
} | ||
} | ||
|
||
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]; | ||
} |
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,50 @@ | ||
#include <iostream> | ||
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; | ||
} |
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,40 @@ | ||
#include <iostream> | ||
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; | ||
} |
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,42 @@ | ||
#include <iostream> | ||
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; | ||
} |
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,53 @@ | ||
#include <iostream> | ||
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; | ||
} |
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,40 @@ | ||
#include <iostream> | ||
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; | ||
} |
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,45 @@ | ||
#include <iostream> | ||
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; | ||
} |