实验一
任务一
tesk1 源代码
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 system("pause"); 9 return 0; 10 }
tesk1测试结果截图

tesk1_1源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main( ) 4 { 5 int i; 6 for( i=0;i<2;i++) 7 { 8 printf(" O\n"); 9 printf("<H>\n"); 10 printf("I I\n"); 11 } 12 system("pause"); 13 return 0; 14 }
tesk1_1测试结果截图

tesk1_2源代码
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 9 system("pause"); 10 return 0; 11 }
tesk1_2测试结果截图

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


任务三
tesk3源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main(){ 4 char ans1,ans2; 5 printf("每天是否温故而知新?(输入Y或y表示有,输入N或n表示没有): "); 6 ans1=getchar(); 7 getchar(); 8 printf("\n动手敲代码了吗?(输入Y或y表示有,输入N或n表示没): "); 9 ans2=getchar(); 10 getchar(); 11 if((ans1=='Y'||ans1=='y')&&(ans2=='Y'||ans2=='y')) 12 printf("/n罗马不是一天建成的,继续保持/n"); 13 else 14 printf("/n罗马不是一天毁灭的,我们来建设吧/n"); 15 system("pause"); 16 return 0; 17 }
tesk3测试结果截图




思考问题回答:
1.添加getchar是为了可以从键盘输入字符,代替了scanf,若去除,则无法输入下一个变量,导致无法输出正确结果,结果截图如下

2.同时,在使用visual stdio 2010时,发现如果只有一个getchar,情况相同,所以上面又添加了一个getchar。
任务四
tesk4源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main(){ 4 double x,y; 5 char c1,c2,c3; 6 int a1,a2,a3; 7 8 scanf("%d%d%d",&a1,&a2,&a3);/*缺少了取地址符*/ 9 printf("a1= %d,a2= %d,a3=%d\n",a1,a2,a3); 10 11 scanf(" %c%c%c",&c1,&c2,&c3); 12 printf("c1=%c,c2=%c,c3=%c\n",c1,c2,c3); 13 14 scanf("%lf,%lf",&x,&y);/*少了一个“l”*/ 15 printf("x=%f,y=%lf\n",x,y); 16 17 system("pause"); 18 return 0; 19 }
若不加2,17行,最后的x,y无法输入
tesk4测试结果截图

任务五
tesk5源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main(){ 4 int year; 5 int a=1e9; 6 double preyearsecond; 7 preyearsecond=365*24*60*60; 8 year=a/preyearsecond+0.5; 9 printf("10亿秒约等于%d年\n",year); 10 system("pause"); 11 return 0; 12 }
tesk5测试结果截图

任务六
tesk6_1源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 int main(){ 5 double x,ans; 6 scanf("%lf",&x); 7 ans=pow(x,365); 8 printf("%.2f的365次方:%.2f\n",x,ans); 9 system("pause"); 10 return 0; 11 }
tesk6_1测试结果截图



tesk6_2源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 int main(){ 5 double x,ans; 6 while(scanf("%lf",&x)!=EOF) 7 { 8 ans=pow(x,365); 9 printf("%.2f的365次方为:%.2f\n",x,ans); 10 } 11 system("pause"); 12 return 0; 13 }
tesk6_1测试结果截图

任务七
tesk7源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 int main(){ 5 double C,F; 6 while(scanf("%lf",&C)!=EOF) 7 { 8 F=(9*C)/5+32; 9 printf("华氏温度为:%.2f\n",F); 10 printf("\n"); 11 } 12 system("pause"); 13 return 0; 14 }
tesk7测试结果截图

任务八
tesk8源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 int main(){ 5 int a,b,c; 6 double s; 7 double S; 8 while(scanf("%d%d%d",&a,&b,&c)!=EOF) 9 { 10 s=(a+b+c)/2; 11 S=sqrt(s*(s-a)*(s-b)*(s-c)); 12 printf("三角形的面积为:%.3f",S); 13 } 14 system("pause"); 15 return 0; 16 }
tesk8测试结果截图

实验总结
1.这次的实验中,最令我印象深刻的是任务四里的“1”与“了“l”,由于其在visual stdio 2010中的长相极其相似(至少在我的电脑上),导致了输出结果的不正常,所以给我的检查造成了很大的干扰;
2.实验四中,对字符量的输出也有了新的经历,更深刻的记住了空格也可被输入,也学会了应对的方法;
3.通过此次的实验,更加深刻的认识到了AI在查错,解惑等方面的好处;
浙公网安备 33010602011771号