实验1

task1_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 
11     return 0;
12 }

task1_2

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

 

task2

 1 #include <stdio.h>
 2 int main()
 3 {
 4     float a, b, c;
 5     printf("输入三边边长:");
 6     
 7     scanf_s("%f%f%f", &a, &b, &c);
 8     if (a + b > c && b + c > a && a + c > b) {
 9         printf("能构成三角形\n");
10     }
11     else {
12         printf("不能构成三角形\n");
13     }
14     return 0;
15 }

 

task3

 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     getchar();
15 
16     if (ans1 == 'y'|| ans1 == 'Y') {
17         if (ans2 == 'y' || ans2 == 'Y') {
18             printf("\n罗马不是一天建成的, 继续保持哦:)\n");
19         }
20         else if (ans2 == 'n' || ans2 == 'N') {
21             printf("\n罗马不是一天毁灭的, 我们来建设吧\n");
22         }
23     }
24     else {
25         printf("\n罗马不是一天毁灭的, 我们来建设吧\n");
26     }
27     
28     return 0;
29 
30 }

 

task4

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

 

task5

 1 #include <stdio.h>
 2 int main()
 3 {
 4     
 5     int year;
 6     int second = 1000000000;
 7 
 8     year = second / (60.0 * 60.0 * 24.0 * 365.0);
 9 
10     printf("10亿秒约等于%d年\n",year);
11 
12     return 0;
13 
14 }

 

task6_1

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

task6_2

 1 #include <stdio.h>
 2 #include <math.h>
 3 int main()
 4 {
 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         printf("\n");
11     }
12     return 0;
13 }

 

task7

 1 #include <stdio.h>
 2 int main()
 3 {
 4     float C = 0;
 5     float F = 0;
 6     printf("请输入摄氏温度:");
 7 
 8     while (scanf("%f", &C) != EOF) {
 9         F = 9.0 * C / 5.0 + 32.0;
10 
11         printf("摄氏温度为%.2f时,华氏度为%.2f", C, F);
12         printf("\n");
13         printf("请输入摄氏温度:");
14     }
15     
16 
17     return 0;
18 }

 

task8

 1 #include <stdio.h>
 2 #include <math.h>
 3 int main()
 4 {
 5     float s,S,area;
 6     int a, b, c;
 7     printf("输入三边边长:");
 8 
 9     while (scanf_s("%d%d%d", &a, &b, &c) != EOF)
10     {
11         
12         if (a + b > c && b + c > a && a + c > b) {
13             s = (a + b + c) / 2.0;
14             S = s * (s - a) * (s - b) * (s - c);
15             area = sqrt(S);
16             printf("a=%d,b=%d,c=%d,area=%f\n", a, b, c, area);
17         }
18         else {
19             printf("不能构成三角形\n");
20         }
21         printf("输入三边边长:");
22     }
23     return 0;
24 }

tip:老师,这个task8我觉得还得加一个判断三角形的一步,这样不会出bug,正好结合task2,温故知新(hhh)

 

posted @ 2023-10-01 22:22  VitaminC++  阅读(11)  评论(0编辑  收藏  举报