实验1

任务1

源代码:

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 int main()
 4 {
 5     int a=1;
 6     do{
 7     printf(" o     o\n"); 
 8     printf("<H>   <H>\n");
 9     printf("I I   I I\n");
10     a++;
11     
12     
13     }while(a==1);
14     system("pause");
15 return 0;
16 }
View Code

运行截图:

 屏幕截图 2026-03-21 131644

源代码:

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 int main()
 4 {
 5     
 6     printf(" o     o\n"); 
 7     printf("<H>   <H>\n");
 8     printf("I I   I I\n");
 9 
10     system("pause");
11 return 0;
12 }
View Code

 

运行截图:

 屏幕截图 2026-03-21 132206

任务2

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 int main()
 4 {
 5     double a,b,c;
 6 
 7     scanf("%lf%lf%lf",&a,&b,&c);
 8     if(a+b>c&&a+c>b&&b+c>a)
 9         printf("能构成三角形\n");
10     else
11         printf("不能构成三角形\n");
12 
13 system("pause");
14 return 0;
15 }
View Code

屏幕截图 2026-03-21 134646

屏幕截图 2026-03-21 134626

任务3

源代码:

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 int main()
 4 {
 5     char ans1,ans2;
 6     printf("每次课前认真预习,课后及时复习了没?('y'or'Y'→yes,'n'or'N'→no)\n");
 7     ans1=getchar();
 8     getchar();
 9     
10     printf("\n动手敲代码实践了没?('y'or'Y'→yes,'n'or'N'→no)\n");
11     ans2=getchar();
12 
13     if((ans1=='y'||ans1=='Y')&&(ans2=='y'||ans2=='Y'))
14         printf("\n罗马不是一天建成的,继续保持哦:)\n");
15     else
16         printf("\n罗马不是一天毁灭的,我们来建设吧!\n");
17     system("pause");
18     return 0;
19 }
View Code

运行截图:

屏幕截图 2026-03-21 141649

问题回答:

getchar()的作用是消掉我们用于分隔输入数据的字符,像回车和tab,如果不加的话,程序将不会等待用户输入第二个答案

任务4

源代码:

 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);//缺少地址符“&”
10     printf("a1=%d,a2=%d,a3=%d\n",a1,a2,a3);
11     getchar();
12 
13     scanf("%c%c%c",&c1,&c2,&c3);
14     printf("c1=%c,c2=%c,c3=%c\n",c1,c2,c3);
15     getchar();
16 
17     scanf("%lf,%lf",&x,&y);//double型数据输入时必须用%lf
18     printf("x=%lf,y=%lf\n",x,y);
19 
20     
21 
22     system("pause");
23     return 0;
24 }
View Code

 

运行截图:

屏幕截图 2026-03-21 145630

任务5

源代码:

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 int main()
 4 {
 5     int year;
 6     int a=1000000000;
 7     year=a/60/60/24/365+0.5;
 8 
 9 
10 
11     printf("10亿秒约等于%d年\n",year);
12     system("pause");
13     return 0;
14 
15 }
View Code

运行截图:

屏幕截图 2026-03-21 151745

 任务6

源代码:

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<math.h>
 4 int main()
 5 {
 6     double x,ans;
 7 
 8     while(scanf("%lf",&x)!=EOF)
 9     {
10         ans=pow(x,365);
11         printf("%.2f的365次方:%.2f\n",x,ans);
12         printf("\n");
13     }
14 
15 
16         system("pause");
17 return 0;
18 }
View Code

运行截图:

屏幕截图 2026-03-21 194929

任务7

源代码:

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<math.h>
 4 int main()
 5 {
 6     double C,F;
 7     while(scanf("%lf",&C)!=EOF)
 8     {
 9     F=9*C/5+32;
10     printf("%.2lf ℃ 等于%.2lf ℉  \n",C,F);
11     
12     }
13 
14 
15 
16 system("pause");
17 return 0;
18 }
View Code

运行截图:

屏幕截图 2026-03-21 200548

任务8

源代码:

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<math.h>
 4 int main()
 5 {
 6     double a,b,c,s,area;
 7     while(scanf("%lf %lf %lf",&a,&b,&c)!=EOF)
 8     {
 9         s=(a+b+c)/2;
10         area=sqrt(s*(s-a)*(s-b)*(s-c));
11         printf("%lf\n",area);
12     }
13 
14 system("pause");
15 return 0;
16 }
View Code

运行截图:

屏幕截图 2026-03-21 202027

 实验总结:

task_1:深化对while函数的理解,应用;?想知道是否有一个函数能横着打印

task_3:输入函数分隔符对。。。的影响,用getchar()吃掉

task_4:tongshang

task_6,7,8:循环的使用,一次性可计算多次

posted @ 2026-03-22 16:20  dfuty  阅读(14)  评论(0)    收藏  举报