- Notifications
You must be signed in to change notification settings - Fork 117
/
Copy path263.c
38 lines (31 loc) · 674 Bytes
/
263.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
#include<stdio.h>
#include<stdbool.h>
#include<assert.h>
boolisUgly(intnum) {
if (num <= 0) return false;
while (num>1) {
boolflag= false;
if (num % 2==0) {
flag= true;
num /= 2;
}
if (num % 3==0) {
flag= true;
num /= 3;
}
if (num % 5==0) {
flag= true;
num /= 5;
}
if (!flag) return false;
}
return true;
}
intmain() {
assert(isUgly(0) == false);
assert(isUgly(1) == true);
assert(isUgly(6) == true);
assert(isUgly(14) == false);
printf("all test passed.\n");
return0;
}