代码任务
min.c leap.c min-array.c
Min

Min of Two
Given two integers a and b, to compute their minimum.
min=min{a,b}
Min of Two
min = a >= b ? b : a;
(条件表达式; 三目运算符)
Do Not Use it Too Much!
Do Not Be Too Clever!
Min of Three
Given three integers a, b, and c, to compute their minimum.
min=min{a,b,c}
Min of a Set of Numbers
Given a set A of integers, to compute their minimum.
min=minA

Leap Year

Leap Year (1): Nested if/else (YES)

Leap Year (2): Nested if/else (NO)

Leap Year (3): else if

Leap Year (4): The Ultimate Version
A year is a leap year if
- it is divisible by 4 but not by 100,
- except that years divisible by 400 are leap years.
Short-circuit Evaluation (短路求值)

Min of a Set of Numbers
Given a set A of integers, to compute their minimum.
min=miniAi
min{3,5,2,7}=min(min(min(3,5),2),7)
For Statement


Increment/Decrement Operators (++, --)
i = 2;
j = i * i++;
-->
#define NUM 5
Symbolic Constants (符号常量)
int numbers[NUM] = {0}; has a fixed size.
Array Initializer (DON’T)
int numbers[NUM] = {};
Forbidden in C99 (Unfortunately!)
Allowed by GCC by default (Unfortunately!!)
Allowed in C23 (Fortunately or not???)
Array Initializer (DON’T)
int numbers[NUM];
numbers may contain garbage values;
always initialize it
Array Initializer (DON’T)
int numbers[];
You must specify the size so that the compiler/runtime can allocate memory for it.
Min of a Set of Input Numbers
min=miniAi