1、(case) 输入一到十二月的任意一个月份的数字,输出该月份的英文单词 2、(switch) 输入学生成绩等级,如果是a b c d,输出"score大于等于60,",最后输出“通过考试",输入的是e,则输出“score小于60”,"没有通过考试" 3、(while) 计算1+2+3+.....+1000。 4、(break) 要求从键盘任意输入两个数求和,然后询问是否执行操作,执行则计算,不执行则跳出。 5、(repeat) 要求从键盘任意输入两个数求乘积,然后询问是否重复操作,直到输入N结束。 6、(if) 计算并输出y的值,其中x的值要求从健盘任意输人,程序如下
时间: 2024-03-09 15:44:26 浏览: 46
1、
```
#include <stdio.h>
int main() {
int month;
printf("请输入月份:");
scanf("%d", &month);
switch (month) {
case 1:
printf("January\n");
break;
case 2:
printf("February\n");
break;
case 3:
printf("March\n");
break;
case 4:
printf("April\n");
break;
case 5:
printf("May\n");
break;
case 6:
printf("June\n");
break;
case 7:
printf("July\n");
break;
case 8:
printf("August\n");
break;
case 9:
printf("September\n");
break;
case 10:
printf("October\n");
break;
case 11:
printf("November\n");
break;
case 12:
printf("December\n");
break;
default:
printf("输入错误,请输入1-12之间的整数\n");
break;
}
return 0;
}
```
2、
```
#include <stdio.h>
int main() {
char grade;
printf("请输入成绩等级:");
scanf("%c", &grade);
switch (grade) {
case 'a':
case 'A':
case 'b':
case 'B':
case 'c':
case 'C':
case 'd':
case 'D':
printf("score大于等于60,");
printf("通过考试\n");
break;
case 'e':
case 'E':
printf("score小于60,");
printf("没有通过考试\n");
break;
default:
printf("输入错误,请输入a、b、c、d、e等级\n");
break;
}
return 0;
}
```
3、
```
#include <stdio.h>
int main() {
int i = 1, sum = 0;
while (i <= 1000) {
sum += i;
i++;
}
printf("1+2+3+...+1000=%d\n", sum);
return 0;
}
```
4、
```
#include <stdio.h>
int main() {
int num1, num2, sum;
char choice;
printf("请输入两个整数:");
scanf("%d%d", &num1, &num2);
printf("是否执行操作?(Y/N):");
scanf(" %c", &choice);
if (choice == 'Y' || choice == 'y') {
sum = num1 + num2;
printf("%d+%d=%d\n", num1, num2, sum);
} else {
printf("不执行操作\n");
}
return 0;
}
```
5、
```
#include <stdio.h>
int main() {
int num1, num2, product;
char choice;
do {
printf("请输入两个整数:");
scanf("%d%d", &num1, &num2);
product = num1 * num2;
printf("%d*%d=%d\n", num1, num2, product);
printf("是否重复操作?(Y/N):");
scanf(" %c", &choice);
} while (choice == 'Y' || choice == 'y');
return 0;
}
```
6、
```
#include <stdio.h>
int main() {
int x, y;
printf("请输入x的值:");
scanf("%d", &x);
if (x < 0) {
y = -1;
} else if (x == 0) {
y = 0;
} else if (x > 0 && x < 10) {
y = 1;
} else {
y = 2;
}
printf("y=%d\n", y);
return 0;
}
```
阅读全文