文章归档文章分类文章标签复制本文标题复制本文地址
随便逛逛

C语言教程

stdbool.h头文件定义了4个宏。

  • bool:定义为_Bool
  • true:定义为1。
  • false:定义为0。
  • __bool_true_false_are_defined:定义为1。
1
2
3
4
5
6
7
bool isEven(int number) {
if (number % 2) {
return true;
} else {
return false;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#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;
}

C语言教程


评论