forked from thantrieu/LearnC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbai3.17.c
92 lines (84 loc) · 1.12 KB
/
bai3.17.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdio.h>
#include <stdbool.h>
bool laSoChan(int n) {
return n % 2 == 0;
}
bool khongTang(int n) {
int i = 10000;
int a, b;
a = n / i;
n %= i;
i /= 10;
while(n > 0) {
b = n / i;
n %= i;
i /= 10;
if(a < b) {
return false;
}
a = b;
}
return true;
}
void lkSoKhongTang() {
int i;
for(i = 11111; i <= 99999; i++) {
if(laSoChan(i) && khongTang(i)) {
printf("%10d", i);
}
}
}
bool khongGiam(int n) {
int i = 10000;
int a, b;
a = n / i;
n %= i;
i /= 10;
while(n > 0) {
b = n / i;
n %= i;
i /= 10;
if(a > b) {
return false;
}
a = b;
}
return true;
}
void lkSoKhongGiam() {
int i;
for(i = 11111; i <= 99999; i++) {
if(!laSoChan(i) && khongGiam(i)) {
printf("%10d", i);
}
}
}
bool ktraTong(int n) {
int tChan = 0;
int tLe = 0;
int c;
while(n > 0) {
c = n % 10;
if(laSoChan(c)) {
tChan += c;
} else {
tLe += c;
}
n /= 10;
}
return tLe == tChan;
}
void lkSoTongBangNhau() {
int i;
for(i = 11111; i <= 99999; i++) {
if(ktraTong(i)) {
printf("%10d", i);
}
}
}
int main() {
// lkSoKhongTang();
// lkSoKhongGiam();
lkSoTongBangNhau();
return 0;
}