实验任务1
task1_1.c
源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 printf(" O\n"); 6 printf("<H>\n"); 7 printf("I I\n"); 8 printf(" O\n"); 9 printf("<H>\n"); 10 printf("I I\n"); 11 system("pause"); 12 return 0; 13 }
运行结果截图

task1_2.c
源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 printf(" O O\n"); 6 printf("<H> <H>\n"); 7 printf("I I I I\n"); 8 system("pause"); 9 return 0; 10 }
运行结果截图

实验任务2
task2.c
源代码
1 #include <stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 double a, b, c; 6 scanf("%lf%lf%lf", &a, &b, &c); 7 if(a+b>c && a+c>b && b+c>a) 8 printf("能构成三角形\n"); 9 else 10 printf("不能构成三角形\n"); 11 system("pause"); 12 return 0; 13 }
运行结果截图

实验任务3
task3.c
源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main(){ 4 char ans1,ans2; 5 printf("预习复习了吗(输入y/Y表示有,输入n或N表示没有):"); 6 ans1=getchar();//输入一个字符,赋值给ans1 7 getchar(); 8 printf("\n动手敲代码实践了没? (输入y或Y表示敲了,输入n或N表示没敲) : "); 9 ans2=getchar(); 10 if((ans1=='y'||ans1=='Y')&&(ans2=='Y'||ans2=='y')) 11 printf("/n罗马不是一天建成的,继续保持噢:)\n"); 12 else 13 printf("\n罗马不是一天毁灭的,我们来建设吧"); 14 system("pause"); 15 return 0; 16 17 }
运行结果截图

回答问题
去掉第9行之后程序会跳过第二个问题的输入,直接执行else分支的输出。第9行是用来清除输入后残留的回车符,去掉它后,第二个输入会读到回车符,导致逻辑判断错误。
实验任务4
task4.c
源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 double x, y; 6 char c1, c2, c3; 7 int a1, a2, a3; 8 9 scanf("%d%d%d", &a1, &a2, &a3);//源代码中a1,a2,a3前面没加占位符& 10 printf("a1 = %d, a2 = %d, a3 = %d\n", a1,a2,a3); 11 12 scanf("%c%c%c", &c1, &c2, &c3); 13 printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3); 14 15 scanf("%lf,%lf", &x, &y);//源代码中第一个是用的%f,但是双精度型的数据应该是用%lf 16 printf("x = %f, y = %lf\n",x, y); 17 system("pause"); 18 return 0; 19 }
运行结果截图

试了很多遍都没有输出正确结果
实验任务5
task5.c
源代码
1 // 计算10亿秒约等于多少年,并打印输出 2 #include <stdio.h> 3 #include<stdlib.h> 4 int main() 5 { 6 int year; 7 int t=1000000000;// 补足代码 8 year=t/(60*60*24*365);// ××× 9 printf("10亿秒约等于%d年\n", year); 10 system("pause"); 11 return 0; 12 }
运行结果截图

实验任务6
task6_2.c
源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 5 int main() 6 { 7 double x,ans; 8 9 while(scanf("%lf",&x) != EOF) 10 { 11 12 ans=pow(x,365); 13 printf("%.2f的365次方:%.2f\n",x,ans); 14 printf("\n"); 15 } 16 17 system("pause"); 18 return 0; 19 }
运行结果截图

按了Ctrl+Z键但是没有终止计算
实验任务7
task7.c
源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int main() 5 { 6 double F,C; 7 while(scanf("%lf", &C) != EOF) 8 { 9 F=1.8*C+32; 10 printf("摄氏度c=%.2f时,华氏度f=: %.2f\n", C, F); 11 printf("\n"); 12 } 13 system("pause"); 14 return 0; 15 }
运行结果截图

按了Ctrl+Z键但是没有终止计算
实验任务8
task8.c
源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 int main() 5 { 6 double a,b,c,s,p; 7 while(scanf("%lf%lf%lf",&a,&b,&c) != EOF) 8 { 9 s=(a+b+c)/2; 10 p=pow(s*(s-a)*(s-b)*(s-c),0.5); 11 printf("a=%f,b=%f,c=%f,area=%.3f\n\n",a,b,c,p); 12 } 13 system("pause"); 14 return 0; 15 }
运行结果截图

按了Ctrl+Z键但是没有终止计算
实验总结
本次实验我还有较大疑惑未能解决:1.像实验678这样的用法实现多组数据输入直至用户同时按下Ctrl+Z键结束运行,为什么我按了好几次都没办法结束运行。2.实验4我按照正确的数据输入方式输入数据,结果还是不对,试了助教给出的关闭正在运行的程序的方法没有用,问了AI,但是没有给出解决方法。
收获也是有的,比如注意分隔符的正确使用。运行框一闪而过可以使用函数解决,让运行框停留。