# data[].attributes.body
int DemDoiXung(int a[], int n)
{
	int dem = 0;
	for(int i = 0; i < n; i++)
	{
		if(a[i] < 0)
		{
			break;
		}
		if(KiemTraDoiXung(a[i]) == 1)
		{
			dem++;
		}
	}
	return dem;
}

# data[].attributes.body
int KiemTraBangNhau(int A[], int n)
{
int kt = 0;
for (int i = 0; i < n - 1; i++)
{
for (int j = i + 1; j < n; j++)
{
if (A[i] == A[j])
{
kt = 1;
break;
}
}
}
return kt;
}

# data[].attributes.body
int KiemTraGiamDan(int A[], int n)
{
int kt = 1;
for (int i = 0; i < n - 1; i++)
{
if (A[i] < A[i + 1])
{
kt= 0;
break;
}
}
return kt;
}

# data[].attributes.body
int KiemTraTangDan(int A[], int n)
{
int kt = 1;
for (int i = 0; i < n - 1; i++)
{
if (A[i] > A[i + 1])
{
kt = 0;
break;
}
}
return kt;
}

# data[].attributes.body
int KiemTraToanChan(int A[], int n)
{
int kt = 1;
for (int i = 0; i < n; i++)
{
if (A[i] % 2 != 0)
{
kt = 0;
break;
}
}
return kt;
}

# data[].attributes.body
int KiemTraNguyenTo(int n)
{
if (n < 2)
{
return 0;
}
else if (n > 2)
{
if (n % 2 == 0)
{
return 0;
}
for (int i = 3; i <= sqrt((float)n); i += 2)
{
if (n % i == 0)
{
return 0;
}
}
}
return 1;

}
int KiemTraMangCoSoNguyenTo(int A[], int n)
{
int kt = 0;
for (int i = 0; i < n; i++)
{
if (KiemTraNguyenTo(A[i]) == 1)
{
kt = 1;
}
}
return kt;
}

# data[].attributes.body
int KiemTraCoSoChan(int A[], int n)
{
int kt = 0;
for (int i = 0; i < n; i++)
{
if (A[i] % 2 == 0)
{
kt = 1;
break;
}
}
return kt;
}

# data[].attributes.body
int KiemTraCo2GiaTri0LienTiep(int A[], int n)
{
int kt = 0;
for (int i = 0; i < n; i++)
{
if (A[i] == 0 && A[i + 1] == 0)
{
kt = 1;
break;
}
}
return kt;
}

# data[].attributes.body
int KiemTraCoGiaTri0(int A [], int n)
{
int kt = 0;
for (int i = 0; i < n; i++)
{
if (A[i] == 0)
{
kt = 1;
}
}
return kt;
}

# data[].attributes.body
int Dem(int *a, int *b, int n, int m)
{
	int i,j,test,dem=0;
	for (i=0; i<m; i++)
	{
		if (b[i]==a[0])
		{
			int h = i;
			for (test=1, j=0; j<n;j++,h++)
			{
				if (a[j] != b[h])
				{
					test = 0;
					break;
				}
			}
			if (test == 1)
				dem++;
		}
	}
	return dem;
}

# data[].attributes.body
bool kiemtramangcon(int *a, int *b, int n, int m)
{
	int i,j,test = false;
	for (i=0; i<m; i++)
	{
		if (b[i]==a[0])
		{
			int h = i;
			for (test=true, j=0; j<n;j++,h++)
			{
				if (a[j] != b[h])
				{
					test = false;
					break;
				}
			}
			if (test == true)
				return test;
		}
	}
	return test;
}

# data[].attributes.body
bool kiemtramangtang(int *b, int nb)
{
	for(int i=0; i<nb-1; i++)
	{
		if (b[i]>b[i+1])
			return false;
	}
	return true;
}


void lietkecontang(int *a, int n)
{
	int ChieuDai;
	int b[100], nb;
	for (int i=0; i<n; i++)
	{
		for (ChieuDai = 1+i; ChieuDai<=n; ChieuDai++)
		{
			nb=0;
			for(int j=i; j<ChieuDai; j++)
			{
				b[nb]=a[j];
				nb++;
			}
			if (kiemtramangtang(b,nb)==1)
			{
				xuatmang(b,nb);
			}
		}
	}
}

# data[].attributes.body
void conlonhonhai(int *a, int n)
{
	int ChieuDai;
	for (int i = 0; i < n; i++)
	{
		for (ChieuDai = 3 + i; ChieuDai <= n; ChieuDai++)
		{
			for (int j = i; j < ChieuDai; j++)
			{
				cout << a[j];
			}
			cout << "\n";
		}
	}
}

# data[].attributes.body
void lietkecon(int *a, int n)
{
int ChieuDai;
for (int i = 0; i<n; i++)
{
for (ChieuDai = 1 + i; ChieuDai <= n; ChieuDai++)
{
for (int j = i; j<ChieuDai; j++)
{
cout << a[j];
}
cout << "\n";
}
}
}

# data[].attributes.body
void dichphai(int *mang, const int n, int k) {
int temp;
for (int j = 1; j <= k;j++) {
temp = mang[n-1];
for (int i = 0; i < n-1; i++) {
temp = mang[i];
mang[i] = mang[i+1];
mang[i+1] = temp;
}
mang[0] = temp;
}
}

# data[].attributes.body
void dichtrai(int *mang, const int n, int k) {
int temp;
for (int j = 1; j <= k;j++) {
temp = mang[0];
for (int i = 1; i < n; i++) {
temp = mang[i];
mang[i] = mang[i-1];
mang[i-1] = temp;
}
mang[n - 1] = temp;
}
}

# data[].attributes.body
void daomang(int *mang, const int n) {
int temp;
for (int i = 0; i < n / 2; i++) {
temp = mang[i];
mang[i] = mang[n - i - 1];
mang[n - i - 1] = temp;
}
}

# data[].attributes.body
void daochan(int *mang, const int n) {
int temp;
for (int i = 0; i < n / 2; i++) {
if (mang[i] % 2 == 0 || mang[n - 1 - i] % 2 == 0) {
temp = mang[i];
mang[i] = mang[n - i - 1];
mang[n - i - 1] = temp;
}
}
}

# data[].attributes.body
void chiahetchoba(int *mang, const int n) {
int vt = 0;
if (mang[0] % 3 == 0) vt++;
for (int i = 1; i < n; i++) {
if (mang[i] % 3 == 0) {
if (vt == i) { vt++; }
else { mang[i] = mang[vt]; mang[vt] = 1; vt++; }
}
}
}

# data[].attributes.body
void chandaulecuoi(int *mang, const int n) {
int vt = 0;
int temp;
if (mang[0] % 2 == 0) vt++;
for (int i = 1; i < n; i++) {
if (mang[i] % 2 == 0) {
if (vt == i) { vt++; }
else {
temp = mang[i];
mang[i] = mang[vt];
mang[vt] = temp;
vt++;
}
}
}
if (mang[vt] == 0) vt++;
for (int i = vt; i < n; i++) {
if (mang[i] == 0) {
if (vt == i) { vt++; }
else {
temp = mang[i];
mang[i] = mang[vt];
mang[vt] = temp;
vt++;
}
}
}
}

# data[].attributes.body
void motvedau(int *mang, const int n) {
int vt = 0;
if (mang[0] == 1) vt++;
for (int i = 1; i < n; i++) {
if (mang[i] == 1) if (vt == i) { vt++; }
else { mang[i] = mang[vt]; mang[vt] = 1; vt++; }
}
}

# data[].attributes.body
void LietKeCacGiaTriXuatHienQua1Lan(int A[], int n)

{

for (int i = 0; i < n; i++)

{

int CheckTrung = KiemTraBiTrung(A, n, i);

if (CheckTrung == 1)

{

int dem = DemSoLuongPhanTuTrung(A, n, i);

if (dem != 1)

{

cout << "\nCac phan tu xuat hien qua 1 lan la: " << A[i];

}

}

}

}

# data[].attributes.body
int KiemTraBiTrung(int A[], int n, int ViTri)
{
for (int i = ViTri - 1; i >= 0; i--)
{
if (A[i] == A[ViTri])
{
return 0;
}
}
return 1;
}

int DemSoLuongPhanTuTrung(int A [], int n, int ViTri)
{
int dem = 1;
for (int i = ViTri + 1; i < n; i++)
{
if (A[i] == A[ViTri])
{
dem++;
}
}
return dem;
}

void LietKeCacGiaTriXuatHienDung1Lan(int A [], int n)
{
for (int i = 0; i < n; i++)
{
int CheckTrung = KiemTraBiTrung(A, n, i);
if (CheckTrung == 1)
{
int dem = DemSoLuongPhanTuTrung(A, n, i);
if (dem == 1)
{
cout << "\nCac phan tu xuat hien dung 1 lan la: " << A[i];
}
}
}
}

# data[].attributes.body
void LietKeTanSuatXuatHien(int A[], int n)
{
for (int i = 0; i < n; i++)
{
int dem = 0;
for (int j = 0; j < n; j++)
{
if (A[i] == A[j])
{
if (i <= j)
{
dem++;
}
else
{
break;
}
}
}
if (dem != 0)
{
cout << "\n Gia tri " << A[i] << " xuat hien  " << dem << " lan.\n";
}
}
}

# data[].attributes.body
int DemTraiDau(int A[], int n)

{

int dem = 0;

for (int i = 0; i < n; i++)

{

if (A[i] * A[i + 1] < 0)

{

dem++;

}

}

if (dem != 0)

{

dem++;

}

return dem;

}

# data[].attributes.body
int DemKeChan(int A[], int n)

{

int dem = 0;

for (int i = 0; i < n; i++)

{

if (A[i] % 2 == 0 && A[i + 1] % 2 == 0)

{

dem++;

}

}

if (dem != 0)

{

dem++;

}

return dem;

}

# data[].attributes.body
int DemSoLuongGiaTriLonNhat(float A[], int n)
{
int dem = 0;
int max = A[0];
for (int i = 0; i < n; i++)
{
if (max == A[i])
{
dem++;
}
else if (A[i] > max)
{
max = A[i];
dem = 1;
}
}
return dem;
}

# data[].attributes.body
int DemSoNguyenTo(int A[], int n)
{
int dem = 0;
for (int i = 0; i < n; i++)
{
if (Ngto(A[i]) == 1)
{
dem++;
}
}
return dem;
}

# data[].attributes.body
int DemCucTri(int A[], int n)

{

int dem = 0;

for (int i = 0; i < n; i++)

{

if (i == 0 && A[i] != A[i + 1])

{

dem++;

}

else if (i == n - 1 && A[i - 1] != A[i])

{

dem++;

}

else if ((A[i - 1] > A[i] && A[i] < A[i + 1]) || (A[i - 1] < A[i] && A[i] > A[i + 1]))

{

dem++;

}

}

return dem;

}

# data[].attributes.body
int tancung5(int A[], int &n) {
int dem = 0;
for (int i = 0; i < n; i++) {
if (A[i] % 10 == 5) {
dem++;
}
}
return dem;
}

# data[].attributes.body
float xanhat(float *a, int n)
{
float x;
cout << "Nhap gia tri can tinh : ";
cin >> x;
float xanhat = a[0] - x;
for (int i = 0; i < n; i++)
if ((a[i] - x)> xanhat) xanhat = a[i] - x;
return xanhat + x;
}

# data[].attributes.body
float vtamlonnhat(float *a, int n)
{
float ammax = amdau(a, n); int k=-1;
for (int i = 0; i < n; i++)
{
if (a[i]<0 && a[i]> ammax)
k = i;
}
if (k == -1) return -1;
return k;
}

# data[].attributes.body
int nguyentolonnhat(int *a, int n)
{
int nguyentomax = nguyentodau(a, n);
if (nguyentomax == -1) return 0;
for (int i = 0; i < n;i++)
if (Ngto(a[i]) == true && Ngto(a[i])> nguyentomax)
nguyentomax = a[i];
return nguyentomax;
}

# data[].attributes.body
int tansuat(float A[], int n,int &x) {
int dem = 0;
cout << "\n Nhap vao gia tri ma ban can tim: ";
cin >> x;
for (int i = 0; i < n; i++) {
if (A[i] ==x) {
dem++;
}
}
return dem;
}

# data[].attributes.body
float amlonnhat(float *a, int n)
{
float ammax = amdau(a, n);
if (ammax == -1) return 0;
for (int i = 0; i < n; i++)
{
if (a[i]<0 && a[i]> ammax) ammax = a[i];
}
return ammax;
}

# data[].attributes.body
int hoanthiencuoi(int *a, int n)
{
for (int i = n - 1; i >= 0;i--)
if (kiemtrahoanthien(a[i]) == true) return a[i];
return -1;
}

# data[].attributes.body
int demchiahetbay(int A[], int &n) {
int dem = 0;
for (int i = 0; i < n; i++) {
if (A[i] < 0 && A[i] % 7 == 0) {
dem++;
}
}
return dem;
}

# data[].attributes.body
int nguyentocuoi(int *a, int n)
{
for (int i = n - 1; i >= 0; i--)
{
if (Ngto(a[i]) == true) return a[i];
}
return -1;
}

# data[].attributes.body
float duongcuoi(float *a, int n)
{
for (int i = n - 1; i >= 0; i--)
if (a[i]>0) return a[i];
return -1;
}

# data[].attributes.body
int amdau(int *a, int n)
{
for (int i = 0; i < n; i++)
{
if (a[i] < 0) return a[i];
}
return -1;
}

# data[].attributes.body
int DemSoChan(int A[], int &n)
{
int dem = 0;
for (int i = 0; i < n; i++)
{
if (A[i] % 2 == 0)
{
dem++;
}
}
return dem;
}

# data[].attributes.body
int hoanthiendau(int *a, int n)
{
for (int i = 0; i < n; i++)
{
if (kiemtrahoanthien(a[i]) == true) return a[i];
}
return -1;
}

# data[].attributes.body
bool Ngto(int n)
{
if (n < 2) return false;
if (n>2)
{
if (n % 2 == 0) return false;
for (int i = 3; i < n; i += 2)
{
if (n%i == 0) return false;
}
}
return true;
}
int nguyentodau(int *a, int n)
{
for (int i = 0; i < n; i++)
if (Ngto(a[i]) == true) return a[i];
return -1;
}

# data[].attributes.body
int chandau(int *a, int n)
{
for (int i = 0; i < n; i++)
if (a[i] % 2 == 0) return a[i];
return -1;
}

# data[].attributes.body
float nhonhat(float *a, int n)
{
float min = a[0];
for (int i = 1; i < n; i++)
{
if (a[i] < min) min = a[i];
}
return min;
}

# data[].attributes.body
int vtduongnhonhat(float *a, int n)
{
int i, min, dem = 0;
for (i = 0; i < n; i++)
{
if (a[i]>0)
{
dem++;
min = i;
break;
}
}
if (dem == 0) return -1;
for (i = i + 1; i < n;i++)
if ((a[i]>0) && (a[i] < a[min])) min = i;
return min;
}

# data[].attributes.body
float duongnhonhat(float *a, int n)
{
float duongnhonhat = duongdautien(a, n);
if (duongnhonhat == -1) return -1;
for (int i = 0; i < n; i++)
{
if (a[i]>0 && a[i] < duongnhonhat) duongnhonhat = a[i];
}
return duongnhonhat;
}

# data[].attributes.body
bool kiemtrahoanthien(int n)
{
int i = 1; int s = 0;
while (i < n)
{
if (n%i == 0) s = s + i;
i++;
}
if (s == n)return true;
return false;
}
int vthoanthiencuoi(int *a, int n)
{
for (int i = n - 1; i >= 0;i--)
if (kiemtrahoanthien(a[i]) == true) return i;
return -1;
}

# data[].attributes.body
int vtchandau(int *a, int n)
{
for (int i = 0; i < n;i++)
if (a[i] % 2 == 0) return i;
return -1;
}

# data[].attributes.body
int vtnhonhat(float *a, int n)
{
int vtnhonhat = 0;
for (int i = 0; i < n; i++)
if (a[i] < a[vtnhonhat]) vtnhonhat = i;
return vtnhonhat;
}

# data[].attributes.body
int timchancuoi(int *a, int n)
{
for (int i = n - 1; i >= 0; i--)
if (a[i] % 2 == 0) return a[i];
return -1;
}

# data[].attributes.body
float duongdautien(float *a, int n)
{
for (int i = 0; i < n; i++)
if (a[i]>0) return a[i];
return -1;
}

# data[].attributes.body
float lonnhat(float *a, int n)
{
float ln = a[0];
for (int i = 0; i < n;i++)
if (a[i]>ln) ln = a[i];
return ln;
}

# data[].attributes.body
void xuat(int *a, int n)
{
for (int i = 0; i < n; i++)
{
cout << a[i] << " ";
}
}

# data[].attributes.body
void xuat(float *a, int n)
{
for (int i = 0; i < n; i++)
{
cout << a[i] << " ";
}
}

# data[].attributes.body
void nhap(float a[], int &n)
{
do
{
cout<<"\nNhap so phan tu: ";
cin >> n;
if (n <= 0 || n > 1000)
{
cout<<"\nSo phan tu khong hop le. Xin kiem tra lai !";
}
} while (n <= 0 || n > 1000);
for (int i = 0; i < n; i++)
{
cout << "Nhap a[" << i << "]: ";
cin >> a[i];
}
}

# data[].attributes.body
void nhap(int a[], int &n)
{
do
{
cout<<"\nNhap so phan tu: ";
cin >> n;
if (n <= 0 || n > 1000)
{
cout<<"\nSo phan tu khong hop le. Xin kiem tra lai !";
}
} while (n <= 0 || n > 1000);
for (int i = 0; i < n; i++)
{
cout << "Nhap a[" << i << "]: ";
cin >> a[i];
}
}

# data[].attributes.body
void kiemtrahoanvi(int *a, int *b, int na; int nb)
{
if(na!=nb)
cout<<"khong phai";
tangdan(a,na);
tangdan(b;nb);
for (int i=0;i<na;i++)
{
if (a[i]!=b[i])
cout<<"khong phai";
}
cout<<"phai";
}

# data[].attributes.body
void vitriamtangdan(int *a, int &n)
{
for (int i=0;i<n;i++)
if(a[i]<0)
for(int j=i+1;j<n;i++)
if a[i]<0 && a[i]>a[j]
hoanvi(a[i],a[j])
}2

# data[].attributes.body
void vitriletangdan(int *a, int &n)
{
for (int i=0;i<n;i++)
if(a[i]%2!=0)
for(int j=i+1;j<n;i++)
if a[i]%2!=0 && a[i]>a[j]
hoanvi(a[i],a[j])
}

# data[].attributes.body
void tangdan(int *a; int &n)

{

for(int i=0;i<n-1;i++)

for(int j=i+1;i<n;j++)

if (a[i]>a[j])

hoanvi(a[i], a[j])

}

# data[].attributes.body
void hoanvi(int &a, int &b)

{

int temp=a;

a=b;

b=temp;

}

void giamdan(int *a; int &n)

{

for(int i=0;i<n;i++)

for (int j=i+1;j<n;j++)

if (a[i]<a[j]);

hoanvi(a[i],a[j])

}

# data[].attributes.body
void themphantu(int *a, int &n, int vitri, int k)
{
do
{
cout<<"nhap vi tri can them"<<o<<"-->"<<n;
cin>>n;
if (vitri <0|| vitri>n)
cout<<"nhap lai";
cin>>n;
}while (vitri<0 || vitri>n)
cout<<"nhap vi tri va k";
cin>>vitri>>k;
n++
for (int i=n;i>vitri;i--)
a[i]=a[i-1];
a[vitri]=k;
}

# data[].attributes.body
void xoacacphantutrungnhau(int a, int &n)
{
	for(int i = 0; i < n; i++)
	{
		for(int j = i + 1; j < n; j++)
		{
			if(a[i] == a[j])
			{
				xoaphantu(a, n, j);
				j--;
			}
		}
	}
}

# data[].attributes.body
void xoacasochan(int a[], int &n)
{
	for(int i = 0; i < n; i++)
	{
		if(a[i] % 2 == 0)
		{
			xoaphantu(a, n, i);
			i--;
		}
	}
}

# data[].attributes.body
void xoacacsoam(int a, int &n)
{
	for(int i = 0; i < n; i++)
	{
		if(a[i] < 0)
		{
			xoaphantu(a, n, i);
			i--;
		}
	}
}

# data[].attributes.body
void xoaphantu(int *a, int &n, int vitrixoa)
{
do{
cout<<"\nNhap vi tri xoa: ";
cin>>n;

if(vitrixoa < 0 || vitrixoa >= n)
{
cout<<"nhap lai";
cin>>vi
}
}while(vitrixoa < 0 || vitrixoa >= n);
for(int i = ViTriXoa; i < n; i++)
{
a[i] = a[i + 1];
}
n- -;
}

# data[].attributes.body
void chẽ_x_vao_mang_tang(int a[], int &n, int x)
{
	int i, j;
	for(i = 0; i < n; i++)
	{
		if(x < a[i])
		{
			int temp = x;
			for(j = n; j > i; j--)
			{
				a[j] = a[j - 1];
			}
			a[i] = temp;
		}
	}
	n++;
}

# data[].attributes.body
float TinhTBCongNguyenTo(int a[], int n)

{

int Tong = 0;

float dem = 0;

for (int i = 0; i < n; i++)

{

if (Ngto(a[i]) == 1)

{

Tong += a[i];

dem++;

}

}

if (dem == 0)

{

std::cout<<"\nMang khong co so nguyen to";

return 0;

}

return Tong / dem;

}

# data[].attributes.body
int KiemTraChuSoDauChan(int n)
{
	while(n >= 10)
	{
		n /= 10;
	}
	if(n % 2 == 0)
	{
		return 1;
	}
	return 0;
}

int TinhTongCacSoChuSoDauChan(int a[], int n)
{
	int Tong = 0;
	for(int i = 0; i < n; i++)
	{
		if(KiemTraChuSoDauChan(a[i]) == 1)
		{
			Tong += a[i];
		}
	}
	return Tong;
}

# data[].attributes.body
int KiemTraDoiXung(int n)
{
	int donvi, tam = n;
	int sodaonguoc = 0;
	while(tam != 0)
	{
		donvi = tam % 10;
		sodaonguoc = sodaonguoc * 10 + donvi;
		tam /= 10;
	}
	if(sodaonguoc == n)
	{
		return 1;
	}
	return 0;
}

int TongCacSoDoiXung(int a[], int n)
{
	int Tong = 0;
	for(int i = 0; i < n; i++)
	{
		if(KiemTraDoiXung(a[i]) == 1)
		{
			Tong += a[i];
		}
	}
	return Tong;
}

# data[].attributes.body
int KiemTraChinhPhuong(int n)
{
	return sqrt((float)n) == (int)sqrt((float)n);
}

int TinhTongCacSoChinhPhuong(int a[], int n)
{
	int Tong = 0;
	for(int i = 0; i < n; i++)
	{
		if(KiemTraChinhPhuong(a[i]) == 1)
		{
			Tong += a[i];
		}
	}
	return Tong;
}

# data[].attributes.body
int TinhTongCacPhanTuCucTri(int a[], int n) { int Tong = 0; for(int i = 0; i < n; i++) { if(i == 0 && a[i] != a[i + 1])

{
Tong += a[i];
}
else if(i == n - 1 && a[i] != a[i - 1])
{
Tong += a[i];
}
else if((a[i] < a[i + 1] && a[i] < a[i - 1]) || (a[i] > a[i + 1] && a[i] > a[i - 1])) { Tong += a[i]; } } return Tong; }

# data[].attributes.body
int TinhTongCacPhanTuLonHonPhanTuXungQuanh(int a[], int n)
{
int Tong = 0;
for (int i = 0; i < n; i++)
{
if (i == 0 && a[i] > a[i + 1])
{
Tong += a[i];
}
else if (i != 0 && a[i] > a[i + 1] && a[i] > a[i - 1])
{
Tong += a[i];
}
else if (i == n - 1 && a[i] > a[i - 1])
{
Tong += a[i];
}
}
return Tong;
}

# data[].attributes.body
int TinhTongCacPhanTuLonHonTriTuyetDoiCuaPhanTuDungLienSauNo(int a[], int n)
{
	int Tong = 0;
	for(int i = 0; i < n; i++)
	{
		if(a[i] > abs(a[i + 1]))
		{
			Tong += a[i];
		}
	}
	return Tong;
}

# data[].attributes.body
int tongcacphantulonhondungtruocno(int a[], int n)
{
int Tong = 0;
for (int i = 1; i < n; i++)
{
if (a[i] > a[i - 1])
{
Tong += a[i];
}
}
return Tong;
}

# data[].attributes.body
int TimSoHangChuc5(int n)
{
n = abs(n);
n = n / 10;
int hangchuc = n % 10;
if (hangchuc == 5)
{
return 1;
}
return 0;
}

int TinhTongSoHangChuc5(int a[], int n)
{
int Tong = 0;
for (int i = 0; i < n; i++)
{
if (TimSoHangChuc5(a[i]) == 1)
{
Tong += a[i];
}
}
return Tong;
}

# data[].attributes.body
int TimChuSoDauLe(int n)
{
int donvi;
n = abs(n);
while (n >= 10)
{
donvi = n % 10;
n /= 10;
}
if (n % 2 == 0)
{
return 0;
}
return 1;
}

int TinhTongCacSoChuSoDauLe(int a[], int n)
{
int Tong = 0;
for (int i = 0; i < n; i++)
{
if (TimChuSoDauLe(a[i]) == 1)
{
Tong += a[i];
}
}
return Tong;
}

# data[].attributes.body
float tinhtongcacphanduong(float a[], int n)
{
	int Tong = 0;
	for(int i = 0; i < n; i++)
	{
		if(a[i] > 0)
		{
			Tong += a[i];
		}
	}
	return Tong;
}

# data[].attributes.body
int TinhTong(int a[], int n)
{
	int tong = 0;
	for(int i = 0; i < n; i++)
	{
		tong += a[i];
	}
	return tong;
}

# data[].attributes.body
void LietKe(int a[], int n)
{
int flag = 0;
for (int i = 0; i < n; i++)
{
if (a[i] > abs(a[i - 1]) && a[i] < abs(a[i + 1]))
{
flag = 1;
std::cout << a[i] << " ";
}
}
if (flag == 0)
std::cout<<"Mang ko co gia tri do";
}

# data[].attributes.body
void LietKe(int a[], int n)
{
int flag = 0;
for (int i = 0; i < n; i++)
{
if (a[i] > abs(a[i + 1]))
{
flag = 1;
std::cout << a[i] << " ";
}
}
if (flag == 0)
std::cout<<"Mang ko co gia tri do";
}

# data[].attributes.body
void LietKeChanTrongDoanXY(int a[], int n, int x, int y)
{
for (int i = 0; i < n; i++)
{
if (a[i] % 2 == 0 && x <= a[i] && a[i] <= y)
{
std::cout<< a[i]<<" ";
}
}
}

# data[].attributes.body
void LietKeTrongDoanXY(float a[], int n, float x, float y)
{
for (int i = 0; i < n; i++)
{
if (x <= a[i] && a[i] <= y)
{
std::cout<<a[i]<<" ";
}
}
}

# data[].attributes.body
void LietKeCacSoAm(float a[], int n)
{
std::cout<<"\nCac so am trong mang la: ";
for (int i = 0; i < n; i++)
{
if (a[i] < 0)
{
std::cout << a[i] << " ";
}
}
}

# data[].attributes.body
int dautientrongdoan(int a[], int n, int x, int y)
{
int dem = 0;
int i;
for (i = 0; i < n; i++)
{
if (a[i] >= x && a[i] <= y)
{
dem++;
break;
}
}
if (dem == 0)
{
return x;
}
return a[i];
}

# data[].attributes.body
float TimAmCuoiCung(float a[], int n)
{
for (int i = n - 1; i >= 0; i--)
{
if (a[i] > -1 && a[i] < 0)
{
return a[i];
}
}
return 0;
}

# data[].attributes.body
float dautien(float a[], int n)
{
for (int i = 0; i < n; i++)
{
if (a[i] > 2003)
{
return a[i];
}
}
return 0;
}

# data[].attributes.body
float timx(float a[], int n)
{
float x = a[0];
for (int i = 1; i < n; i++)
{
x = (x >(fabs)(a[i])) ? x : (fabs)(a[i]);
}
return x;
}

# data[].attributes.body
void nhap (int *a, int &n)
{
do
{
cout<<"\nNhap so phan tu: ";
cin<<n;
if(n <= 0 || n > MAX)
{
cout<<"\nnhap lai";
cin>>n;
}
}while(n <= 0 || n > MAX);
for(int i = 0; i < n; i++)
{
cout<<"\na["<<i<<]=;
cin>>a[i];
for(int j = 0; j < i; j++)
{
if(a[i] > a[j])
{
int temp = a[i];
for(int k = i; k > j; k--)
{
a[k] = a[k - 1];
}
a[j] = temp;
}
}
}
}

# data[].attributes.body
void timdoan(float a[], int n)
{
float max = a[0];
float min = a[0];
for (int i = 0; i < n; i++)
{
max = (a[i] > max) ? a[i] : max;
min = (a[i] < min) ? a[i] : min;
}
std::cout<<"\n["<<min<<","<<max<<" ] la doan chua cac gia tri trong mang\n";
}

# data[].attributes.body
void TaoMang(float a[], int n, float b[], int x)

{

for (int i = 0; i < n; i++)

{

b[i] = abs(x - a[i]);

}

}

float TimMin(float b[], int n)

{

float Min = b[0];

for (int i = 1; i < n; i++)

{

if (b[i] < Min)

{

Min = b[i];

}

}

return Min;

}

void XuatKetQua(float a[], float b[], int n)

{

std::cout<<"\nGia tri trong mang gan gia tri x nhat la: ";

float Min = TimMin(b, n);

for (int i = 0; i < n; i++)

{

if (b[i] == Min)

{

std::cout<<a[i]<<std::endl;

}

}

}

# data[].attributes.body
int hoanthiennhonhat(int *a, int n)

{

int hoanthienmin = hoanthiendau(a, n);

if (hoanthienmin == -1) return 0;

for (int i = 0; i < n; i++)

{

if (kiemtrahoanthien(a[i])==1 && a[i]<hoanthienmin)

{

a[i] = hoanthienmin;

}

}

return hoanthienmin;

}

# data[].attributes.body
int channhonhat(int a[], int n)

{

int chanmin = chandau(a, n);

if (chanmin == -1) return 0;

for (int i = 0; i < n; i++)

{

if (a[i] % 2 == 0 && a[i] < chanmin)

{

a[i] = chanmin;

}

}

return chanmin;

}