#include <stdio.h> int main() { int age = 73; if (age < 18)//if语句后面不要有";"分号。else if和esle后面也不能有!! printf("未成年\n");//一个if语句或者else if或者else语句只能管理 //一个printf,若想管理多个printf要在if或else if语句下面加上{} else if (age < 26) printf("青年\n"); //else if (18 <= age < 26) // printf("青年\n"); // else if (18 <= age < 26)这样写是不行的。因为当age=48时, // 18<=age会被判定为“真”,计算机里“真”默认是1, //那么18<=age这个式子就会变成数字1,那么1<26也就符合了, //所以就会出现age=48,但是输出的是“青年”。要这样写才行 //else if(age>=18 && age<26)其中“&&”两个取地址符号表示 //“并且”的意思。还可以写成:else if(age<26) else if (age < 50) printf("中年\n"); else if (age >= 50 && age < 70) { printf("老年\n"); printf("祝您健康长寿\n"); } else//else与离它最近的if进行匹配,不管对齐不对齐 printf("长寿\n"); return 0; }