作业1
输出结果1:num=7,num2=3,num3=4
输出结果2: num=7,num2=4,num3=5
输出结果3: num=0,num2=5,num3=6
输出结果4: num=1,num2=4,num3=5
输出结果5: num=5,num2=4,num3=6
1 #include<string.h>
2 #include<stdio.h>
3 #include<stdlib.h>
4 int main(int argc, const char *argv[])
5 {
6 float F,C;
7 printf("输入华氏温度: ");
8 scanf("%f",&F);
9 C=(5.0/9)*(F-32);
10 //保证输出为浮点数改成5.0
11 printf("摄氏温度为:%.2f\n",C);
12 return 0;
13 }
1 #include<string.h>
2 #include<stdio.h>
3 #include<stdlib.h>
4 int main(int argc, const char *argv[])
5 {
6 int a,b; //表达式输入的数
7 char num; //结果
8 printf("输入的运算关系式: ");
9 scanf("%d%c%d",&a,&num,&b);
10 switch(num)
11 {
12 case '+':
13 {
14 printf("%d\n",a+b);
15 }
16 break;
17 case '-':
18 {
19 printf("%d\n",a-b);
20 }
21 break;
22 case '*':
23 {
24 printf("%d\n",a*b);
25 }
26 break;
27 case '/':
28 {
29 printf("%d\n",a/b);
30 }
31 break;
32
33 default:
34 printf("error\n");
35 break;
36 }
37 return 0;
38 }
1 #include<string.h>
2 #include<stdio.h>
3 #include<stdlib.h>
4 int main(int argc, const char *argv[])
5 {
6 int year,month,day;
7 printf("请输入年月日: ");
8 scanf("%d%d%d",&year,&month,&day);
9 int num=0;
10 switch(month)
11 {
12 case 12:
13 num += 30;
14 case 11:
15 num += 31;
16 case 10:
17 num += 30;
18 case 9:
19 num += 31;
20 case 8:
21 num += 31;
22 case 7:
23 num += 30;
24 case 6:
25 num += 31;
26 case 5:
27 num += 30;
28 case 4:
29 num += 31;
30 case 3:
31 if((year%4==0&&year%100!=0)||year%400==0)
32 {
33 num += 29;
34
35 }//闰年有29天
36 else
37 {
38 num += 28;
39 }
40 case 2:
41 num +=31;
42 case 1:
43 num += 0;
44
45 }
46 printf("%d\n",num+day);//加上本月的天数
47 return 0;
48 }