0% found this document useful (0 votes)
7 views3 pages

Tài liệu

Uploaded by

2254052055nhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Tài liệu

Uploaded by

2254052055nhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<iostream>

Using namespace std;

Void taoMang(int a[], int n)

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

A[i] =rand () % 100;

Void xuat(int a[], int n) {

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

Cout << a[i] << “ “;

Int TongPTChan(int a[], int n)

Int i, tong = 0, flag = 0;

For (i = 0; i < n; i++)

If (a[i] % 2 == 0)

Flag = 1;

Tong = tong + a[i];

If (flag == 1)

Return tong;

Return -1;

Void HoanVi(int& x, int& y)

Int q = x;

X = y;

Y = q;

Void sochantang(int a[], int n)


{

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

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

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

Int x = a[i];

A[i] = a[j];

A[j] = x;

If (a[i] % 2 == 0) {

Cout << a[i] << “ “;

Void solegiam(int a[], int n)

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

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

If (a[i] < a[j])

Int x = a[i];

A[i] = a[j];

A[j] = x;

If (a[i] % 2 != 0) {
Cout << a[i] << “ “;

Int main()

Int a[1000];

Int n,kq;

Cout << “Nhap n: “;

Cin >> n;

taoMang(a, n);

cout << “Xuat mang: “;

xuat(a, n);

kq = TongPTChan(a, n);

cout << “\nTong cac phan tu chan co trong mang la: “ << kq;

cout << “\nCac phan tu chan trong mang tang dan: “;

sochantang(a, n);

cout << “\nCac phan tu le trong mang giam dan: “;

solegiam(a, n);

cout << endl;

system(“pause”);

return 0;

You might also like