#12916. C语言选择结构单选题
C语言选择结构单选题
题号: 1 类型: 选择题 题目: 以下哪个C语言条件语句会正确判断一个整数是否为偶数?
{{ select(1) }}
- if(num % 2 == 0) { printf("偶数"); } else { printf("奇数"); }
- if(num / 2 == 0) { printf("偶数"); } else { printf("奇数"); }
- if(num % 2 == 1) { printf("偶数"); } else { printf("奇数"); }
- if(num == 2) { printf("偶数"); } else { printf("奇数"); }
题号: 2 类型: 选择题 题目: 以下哪个C语言代码片段会根据输入的成绩(score)输出对应的等级(A、B、C或D)?比如90以上含有90评分为A,以此类推。
{{ select(2) }}
- if(score >= 90) { printf("A"); } else if(score >= 80) { printf("B"); } else if(score >= 70) { printf("C"); } else { printf("D"); }
- if(score > 90) { printf("A"); } else if(score > 80) { printf("B"); } else if(score > 70) { printf("C"); } else { printf("D"); }
- if(score = 90) { printf("A"); } else if(score = 80) { printf("B"); } else if(score = 70) { printf("C"); } else { printf("D"); }
- if(score >= 90) { printf("A"); } if(score >= 80) { printf("B"); } if(score >= 70) { printf("C"); } else { printf("D"); }
题号: 3 类型: 选择题 题目: 以下哪个C语言代码片段会正确实现:如果x大于y,则交换x和y的值?
{{ select(3) }}
- if(x < y) { int temp = x; x = y; y = temp; }
- if(x > y) { x = y; y = x; }
- if(x > y) { int temp = y; y = x; x = temp; }
- if(x < y) { int temp = x; x = y; y = temp; }
题号: 4 类型: 选择题 题目: 以下哪个C语言代码片段会正确实现:当用户输入的数字num为正数时输出"Positive",为负数时输出"Negative",为零时输出"Zero"?
{{ select(4) }}
- if(num > 0) { printf("Positive"); } else if(num < 0) { printf("Negative"); } else { printf("Zero"); }
- if(num >= 0) { printf("Positive"); } else { printf("Negative"); }
- if(num == 0) { printf("Zero"); } else { printf("Positive"); }
- if(num > 0) { printf("Positive"); } if(num < 0) { printf("Negative"); } else { printf("Zero"); }
题号: 5 类型: 选择题 题目: 以下哪个C语言代码片段会正确实现:当输入的字符ch是大写字母时,将其转换为小写字母?
{{ select(5) }}
- if(ch >= 'A' && ch <= 'Z') { ch = ch + ('a' - 'A'); }
- if(ch >= 'a' && ch <= 'z') { ch = ch - ('a' - 'A'); }
- if(ch >= 'A' || ch <= 'Z') { ch = ch + ('a' - 'A'); }
- if(ch >= 'A' && ch <= 'Z') { ch = ch - ('a' - 'A'); }
相关
在以下作业中: