12.stdbool.h
# stdbool.h
stdbool.h头文件定义了4个宏。
bool:定义为_Bool。true:定义为1。false:定义为0。__bool_true_false_are_defined:定义为1。
bool isEven(int number) {
if (number % 2) {
return true;
} else {
return false;
}
}
1
2
3
4
5
6
7
2
3
4
5
6
7
#include <stdio.h>
#include <stdbool.h>
int main(void) {
unsigned long num;
unsigned long div;
bool isPrime = true;
num = 64457;
for (div = 2; (div * div) <= num; div++) {
if (num % div == 0) isPrime = false;
}
if (isPrime) {
printf("%lu is prime.\n", num);
} else {
printf("%lu is not prime.\n", num);
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
上次更新: 2026/06/10, 11:13:41