实验1

实验任务1

源代码

#include<stdio.h>

int main()
{
    printf(" o \n");
    printf("<h>\n");
    printf("I I\n");
    
    return 0;
}

运行截图

捕获

tast1-1

源代码

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

运行截图

 屏幕截图 2025-09-28 130431

 

tast1-2

源代码

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

运行截图

屏幕截图 2025-09-28 130128

 

 实验任务2

 tast2

源代码

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

运行截图

屏幕截图 2025-09-28 131727

屏幕截图 2025-09-28 131839

屏幕截图 2025-09-28 131952

实验任务3

源代码

 

 1 #include <stdio.h>
 2 int main()
 3 {
 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  if ((ans1 == 'y' || ans1 == 'Y') && (ans2 == 'Y' || ans2 == 'y')) 
11  printf("\n罗马不是一天建成的, 继续保持哦:)\n");
12  else
13  printf("\n罗马不是一天毁灭的, 我们来建设吧\n");
14  return 0;
15 }

 运行截图

屏幕截图 2025-09-29 173707

思考:当把源代码line9去掉后,重新编译运行,结果没有ans2,因为输入函数 getchar()处理字符时,回车键产生的 '\n' 会留在输入缓冲区,若不主动清理,会跳过第二次运行

实验任务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  return 0;
18 }

运行截图

屏幕截图 2025-09-29 174718

实验任务5

源代码

 

// 计算10亿秒约等于多少年,并打印输出
#include <stdio.h>

int main() 
{
    int year;

    // 补足代码
    year = 1000000000 / (60 * 60 * 24 * 365);
    printf("10亿秒约等于%d年\n", year);

    printf("10亿秒约等于%d年\n", year);
    return 0;
}

运行截图

屏幕截图 2025-09-29 175549

 实验任务6

源代码

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

运行截图

屏幕截图 2025-09-30 124012

实验任务7

源代码

 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     double f,c;
 6     while (scanf_s("%lf", &c) != EOF)
 7     {
 8         f = 9 * c / 5 + 32;
 9         printf("摄氏度c=%.2lf时,华氏度f=%.2lf", c,f);
10     }
11     
12     return 0;
13 }

运行截图

屏幕截图 2025-09-30 124308

实验任务8

源代码

 1 #include <stdio.h>
 2 #include <math.h>
 3 int main() 
 4 {
 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("a = %.0f, b = %.0f, c = %.0f, area = %.3f\n", a, b, c, area);
12     }
13     return 0;
14 }

运行截图

屏幕截图 2025-09-30 130110

 

posted @ 2025-09-30 13:08  humeop  阅读(8)  评论(1)    收藏  举报