forked from thantrieu/LearnC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbai4.7.c
More file actions
50 lines (42 loc) · 695 Bytes
/
bai4.7.c
File metadata and controls
50 lines (42 loc) · 695 Bytes
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
#include <stdio.h>
void nhap(int *arr, int *n) {
*n = 0;
while(*n <= 0) {
printf("Nhap n > 0: ");
scanf("%d", n);
}
int i;
for(i = 0; i < *n; i++) {
printf("arr[%d] = ", i);
scanf("%d", &arr[i]);
}
}
void nhapAB(int *a, int *b) {
while(1) {
printf("Nhap a < b: ");
scanf("%d%d", a, b);
if(*a < *b) {
break;
}
}
}
int tinhTong(int *arr, int n, int a, int b) {
int tong = 0;
int i;
for(i = 0; i < n; i++) {
if(arr[i] >= a && arr[i] <= b) {
tong += arr[i];
}
}
return tong;
}
int main() {
int n;
int arr[100];
nhap(arr, &n);
int a, b;
nhapAB(&a, &b);
int tong = tinhTong(arr, n, a, b);
printf("TONG [%d, %d] = %d", a, b, tong);
return 0;
}