-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVD2main.cpp
76 lines (57 loc) · 1.33 KB
/
VD2main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
using namespace std;
#include<math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int getData() {
int N;
int t;
float avg;
cout << "Nhap so N: ";
cin >> N;
cout << "Nhap so avg: ";
cin >> avg;
int *D = new int[N];
for(int i=0; i<N; i++) {
printf(" ");
printf("Nhap phan tu thu %d : ", i);
scanf("%d", &D[i]);
}
printf("Gia tri mang: ");
for (int i = 0; i <N; i++) {
printf(" %d ", D[i]);
}
int tong = 0;
for (int i = 0; i <N; i++) {
if(D[i] > sqrt(avg)) {
tong = tong + D[i];
}
}
printf("\n Tong cua mang %d : ", tong);
printf("\n Sap xep mang theo thu tu tang dan ");
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (D[i] > D[j]) {
int temp = D[i];
D[i] = D[j];
D[j] = temp;
}
}
}
printf("\nGia tri mang: ");
for (int i = 0; i <N; i++) {
printf(" %d ", D[i]);
}
int min;
for (int i = 0; i <N; i++) {
if(D[i] > avg) {
min = D[i];
printf("\n So be nhat trong mang lon hon avg: %d ", min);
return 0;
}
}
return 0;
}
int main(int argc, char** argv) {
getData();
return 0;
}