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

Commit

Permalink
💥 (Bai 196 → 231): Done
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Nov 13, 2023
1 parent 59cfd85 commit 58c8da0
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 2 deletions.
49 changes: 48 additions & 1 deletion Bai196/Source.cpp
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];
}
37 changes: 36 additions & 1 deletion Bai201/Source.cpp
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];
}
42 changes: 42 additions & 0 deletions Bai206/Source.cpp
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;
}
32 changes: 32 additions & 0 deletions Bai211/Source.cpp
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;
}
34 changes: 34 additions & 0 deletions Bai216/Source.cpp
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;
}
45 changes: 45 additions & 0 deletions Bai221/Source.cpp
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;
}
32 changes: 32 additions & 0 deletions Bai226/Source.cpp
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;
}
37 changes: 37 additions & 0 deletions Bai231/Source.cpp
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;
}

0 comments on commit 58c8da0

Please sign in to comment.