题目一:

应通过此题加强对switch语句使用的熟练度,switch语句中细节非常多,应当注重语言的准确性。
标准形式:
Switch语句
switch(整型表达式) { ??语句项; }
case 整形常量表达式: ??语句;

题目二:

注意if和else语句的使用,和书写风格,此题也要注意%g强制类型转换的重要性。
%g ? ?根据数值不同自动选择%f或%e
%g用来输出实数,它根据数值的大小,自动选f格式或e格式(选择输出时占宽度较小的一种),且不输出无意义的0
?
题目3: ?大致思路:
#include <stdio.h> #include <stdlib.h>
int main() { ?? ?int year, month, day; ?? ?int yd, md; // 定义年份和月份代码 ?? ?int dh; // 定义dh为代码和 ?? ?int xin; ?? ?scanf("%d%d%d", &year, &month, &day); ?? ?int yushu1, yushu2; ?? ?yd = ((year % 100) / 4 + (year % 100)) % 7; ?? ?yushu1 = year % 4; ?? ?yushu2 = year % 100; ?? ?if (yushu1 = 0 && yushu2 != 0) // 能被4整除不能被100整除是闰年 ?? ?{ ?? ??? ?if (month == 1) ?? ??? ?{ ?? ??? ??? ?md = 5; ?? ??? ?} ?? ??? ?if (month == 2) ?? ??? ?{ ?? ??? ??? ?md = 1; ?? ??? ?} ?? ??? ?if (month == 3) ?? ??? ?{ ?? ??? ??? ?md = 2; ?? ??? ?} ?? ??? ?if (month == 4) ?? ??? ?{ ?? ??? ??? ?md = 5; ?? ??? ?} ?? ??? ?if (month == 5) ?? ??? ?{ ?? ??? ??? ?md = 0; ?? ??? ?} ?? ??? ?if (month == 6) ?? ??? ?{ ?? ??? ??? ?md = 3; ?? ??? ?} ?? ??? ?if (month == 7) ?? ??? ?{ ?? ??? ??? ?md = 5; ?? ??? ?} ?? ??? ?if (month == 8) ?? ??? ?{ ?? ??? ??? ?md = 1; ?? ??? ?} ?? ??? ?if (month == 9) ?? ??? ?{ ?? ??? ??? ?md = 4; ?? ??? ?} ?? ??? ?if (month == 10) ?? ??? ?{ ?? ??? ??? ?md = 6; ?? ??? ?} ?? ??? ?if (month == 11) ?? ??? ?{ ?? ??? ??? ?md = 2; ?? ??? ?} ?? ??? ?if (month == 12) ?? ??? ?{ ?? ??? ??? ?md = 4; ?? ??? ?} ?? ??? ?xin = (day + md + yd) % 7; ?? ??? ?switch (xin) ?? ??? ?{ ?? ??? ?case 1:printf("Monday\n"); ?? ??? ??? ?break; ?? ??? ?case 2:printf("Tuesday\n"); ?? ??? ??? ?break; ?? ??? ?case 3:printf("Wednesday\n"); ?? ??? ??? ?break; ?? ??? ?case 4:printf("Thursday\n"); ?? ??? ??? ?break; ?? ??? ?case 5:printf("Friday\n"); ?? ??? ??? ?break; ?? ??? ?case 6:printf("Saturday\n"); ?? ??? ??? ?break; ?? ??? ?case 7:printf("Sunday\n"); ?? ??? ??? ?break; ?? ??? ?} ?? ?} ?? ?else ?? ?{ ?? ??? ?if (month == 1) ?? ??? ?{ ?? ??? ??? ?md = 6; ?? ??? ?} ?? ??? ?if (month == 2) ?? ??? ?{ ?? ??? ??? ?md = 2; ?? ??? ?} ?? ??? ?if (month == 3) ?? ??? ?{ ?? ??? ??? ?md = 2; ?? ??? ?} ?? ??? ?if (month == 4) ?? ??? ?{ ?? ??? ??? ?md = 5; ?? ??? ?} ?? ??? ?if (month == 5) ?? ??? ?{ ?? ??? ??? ?md = 0; ?? ??? ?} ?? ??? ?if (month == 6) ?? ??? ?{ ?? ??? ??? ?md = 3; ?? ??? ?} ?? ??? ?if (month == 7) ?? ??? ?{ ?? ??? ??? ?md = 5; ?? ??? ?} ?? ??? ?if (month == 8) ?? ??? ?{ ?? ??? ??? ?md = 1; ?? ??? ?} ?? ??? ?if (month == 9) ?? ??? ?{ ?? ??? ??? ?md = 4; ?? ??? ?} ?? ??? ?if (month == 10) ?? ??? ?{ ?? ??? ??? ?md = 6; ?? ??? ?} ?? ??? ?if (month == 11) ?? ??? ?{ ?? ??? ??? ?md = 2; ?? ??? ?} ?? ??? ?if (month == 12) ?? ??? ?{ ?? ??? ??? ?md = 4; ?? ??? ?} ?? ??? ?xin = (day + md + yd) % 7; ?? ??? ?switch (xin) ?? ??? ?{ ?? ??? ?case 1:printf("Monday\n"); ?? ??? ??? ?break; ?? ??? ?case 2:printf("Tuesday\n"); ?? ??? ??? ?break; ?? ??? ?case 3:printf("Wednesday\n"); ?? ??? ??? ?break; ?? ??? ?case 4:printf("Thursday\n"); ?? ??? ??? ?break; ?? ??? ?case 5:printf("Friday\n"); ?? ??? ??? ?break; ?? ??? ?case 6:printf("Saturday\n"); ?? ??? ??? ?break; ?? ??? ?case 7:printf("Sunday\n"); ?? ??? ??? ?break; ?? ??? ?} ?? ?} ?? ?return 0; }
?
题目4:


int main() { ?? ?int number; ?? ?scanf("%d", &number); ?? ?if (number % 2 == 0) ?? ??? ?printf("even number"); ?? ?else ?? ??? ?printf("odd number"); ?? ?return 0; }
题目5:


int main() {
?? ?char op[10]; ?? ?scanf("%c",op); ?? ?if (*op <= 32) ?? ?{ ?? ??? ?printf("This is a control character."); ?? ??? ? ?? ?} ?? ?else if (*op >= '0'&&*op <= '9') ?? ?{ ?? ??? ?printf("This is a digit."); ?? ? ?? ?} ?? ?else if (*op >= 'A'&&*op <= 'Z') ?? ?{ ?? ??? ?printf("This is a capital letter.");
?? ?} ?? ?else if (*op >= 'a'&&*op <= 'z') ?? ?{ ?? ??? ?printf("This is a small letter."); ?? ? ?? ?} ?? ?else ?? ?{ ?? ??? ?printf("This is an other character."); ?? ? ?? ?} ?? ?return 0; } ?
|