实验1

实验任务一:

程序:

 1 //打印一个字符小人
 2 
 3 #include<stdio.h>
 4 #include<stdlib.h>
 5 int main()
 6 {
 7     printf(" o \n");
 8     printf("<H>\n");
 9     printf("I I\n");
10 
11     system("pause");
12 
13     return 0;
14 }
View Code
View Code
 1 //打印一个字符小人
 2 
 3 #include<stdio.h>
 4 #include<stdlib.h>
 5 int main()
 6 {
 7     printf(" o     o\n");
 8     printf("<H>   <H>\n");
 9     printf("I I   I I\n");
10 
11     system("pause");
12 
13     return 0;
14 }
View Code

 

截图:

            

           

 

试验任务2:

程序:

View Code

 

截图:

 

 实验任务3:

 程序:

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 int main()
 4 {
 5     char ans1, ans2;//保存输入的答案
 6 
 7     printf("学习认真否?(y/Y是有,f/F是否):");
 8     ans1 = getchar();
 9 
10     getchar();//记得删除比较
11 
12     printf("代码实践否?(y/Y是有,f/F是否):");
13     ans2 = getchar();
14 
15     if ((ans1 == 'y' || ans1 == 'Y') && (ans2 == 'y' || ans2 == 'Y'))
16         printf("\n美哉\n");
17     else
18         printf("\n怠矣\n");
19 
20     system("pause");
21 
22     return 0;
23 }
View Code

截图:

回答:删去这一行后不能第二次输入,会直接结束程序。

  因为第一次在输入时,输入了字符和换行,第二次输入开始会读取换行直接跳过,因此需要先清除上一次的换行符。 

 

 

实验任务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 
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);//输入必须为%lf
16     printf("x=%lf,y=%lf\n ", x, y);
17 
18     system("pause");
19 
20     return 0;
21 }
View Code

 

截图:

 

 

实验任务5:

程序:

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

截图:

 

 

实验程序6:

 程序:

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

截图:

 

 

实验程序7:

程序:

 1 #define _CRT_SECURE_NO_WARNINGS
 2 #include<stdio.h>
 3 #include<math.h>
 4 #include<stdlib.h>
 5 int main()
 6 {
 7     double c,f;
 8 
 9     while (scanf("%lf", &c) != EOF)
10     {
11         f = (9.0/5 * c) + 32;
12         printf("%.2f摄氏度对应华氏度为:%.2f\n", c, f);
13         printf("\n");
14     }
15 
16     system("pause");
17 
18     return 0;
19 }
View Code

截图:

 

实验程序8:

程序:

 1 #define _CRT_SECURE_NO_WARNINGS
 2 #include<stdio.h>
 3 #include<math.h>
 4 #include<stdlib.h>
 5 int main()
 6 {
 7     double a,b,c,s,S;
 8 
 9     while (scanf("%lf%lf%lf", &a,&b,&c) != EOF)
10     {
11         s = (a + b + c) / 2.0;
12         S = sqrt(s * (s - a) * (s - b) * (s - c));
13         printf("%.3f%.3f%.3f输入三边对应面积为:%.3f\n", a,b,c, S);
14         printf("\n");
15     }
16 
17     system("pause");
18 
19     return 0;
20 }
View Code

截图:

 

 

实验总结:

从零开始学习,还是需要注意前后对应。

        如在需要输入多个数据时,读取的%lf也要有对应的数量。前后括号可以提前打出防止忘记。还有最重要的一点——换行符还有加分号。

posted @ 2025-03-06 13:03  朱云帅  阅读(28)  评论(0)    收藏  举报