实验1

实验任务1

源代码(竖直):

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

运行结果:

image

 源代码(水平):

 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

运行结果:

image

 

 

实验任务2

源代码:

 1 #include <stdio.h>
 2 
 3 int main() 
 4 {
 5     double a, b, c;
 6 
 7     // 输入三边边长
 8     scanf("%lf%lf%lf", &a, &b, &c);
 9 
10     // 判断能否构成三角形
11     // 补足括号里的逻辑表达式
12     if((a+b>c)&&(a+c>b)&&(b+c>a))
13         printf("能构成三角形\n");
14     else
15         printf("不能构成三角形\n");
16 
17     return 0;
18 }
View Code

运行结果:

image    image   

 

 

实验任务3

源代码:

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

运行结果:

image

image

 

 

实验任务4

源代码:

 1 #include<stdio.h>
 2 
 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);
16     printf("x = %f, y = %lf\n",x, y);
17 
18     return 0;
19 }
View Code

运行结果:

image

 

 

实验任务5

源代码:

 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     int year;
 6 
 7     double seconds = 1e9;
 8     double seconds_per_year = 365.0 * 24 * 3600;
 9     double years = seconds / seconds_per_year;
10 
11     year = (int)(years + 0.5);
12 
13     printf("10亿秒约等于%d年\n", year);
14     return 0;
15 }
View Code

运行结果:

image

 

 

实验任务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     system("pause");
15     return 0;
16 }
View Code

运行结果:

image

 

 

实验任务7

源代码:

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

运行结果:

image

 

 

实验任务8

源代码:

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<math.h>
 4 int main()
 5 {
 6     double area, a, b, c, s;
 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("a = %.3f, b = %.3f, c = %.3f, area = %.3f\n",a, b, c, area);
12         printf("\n");
13     }
14     system("pause");
15     return 0;
16 }
View Code

运行结果:

image

 

posted @ 2026-03-23 17:16  yailly  阅读(13)  评论(0)    收藏  举报