张致宁 信息与计算科学+人工智能

实验1

1.实验任务1

源代码:

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

实验截图:

实验1.1

1.1实验任务1_1

源代码:

 1 #include<stdio.h>
 2 #include<stdlib.h>
 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     system("pause");
12     return 0;
13 }

实验截图:

实验1_1

1.2实验任务1_2

实验代码:

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

实验截图:

实验1_2

 

实验2

源代码

 1 // 从键盘上输入三个数据作为三角形边长,判断其能否构成三角形
 2 // 构成三角形的条件: 任意两边之和大于第三边
 3 
 4 #include <stdio.h>
 5 #include<stdlib.h>
 6 int main() 
 7 {
 8     double a, b, c;
 9 
10     // 输入三边边长
11     scanf("%lf%lf%lf", &a, &b, &c);
12 
13     // 判断能否构成三角形
14     // 补足括号里的逻辑表达式
15     if(a+b>=c&&a+c>=b&&b+c>=a)
16         printf("能构成三角形\n");
17     else
18         printf("不能构成三角形\n");
19     system("pause");
20     return 0;
21 }

实验截图

任务2实验截图

image

image

 

实验三

源代码

 1 #include <stdio.h>
 2 #include<stdlib.h>
 3 int main()
 4 {
 5     char ans1, ans2;  // 用于保存用户输入的答案
 6 
 7     printf("每次课前认真预习、课后及时复习了没? (输入y或Y表示有,输入n或N表示没有) :  ");
 8     ans1 = getchar(); // 从键盘输入一个字符,赋值给ans1
 9 
10     getchar(); // 思考这里为什么要加这一行。试着去掉这一行,看看对运行有没有影响。
11 
12     printf("\n动手敲代码实践了没? (输入y或Y表示敲了,输入n或N表示木有敲) :  ");
13     ans2 = getchar();
14 
15     if ((ans1=='y'||ans1=='Y')&&(ans2=='Y'||ans2=='y')) // 待补足,判断用户回答ans1和ans2都是y(不区分大小写)
16         printf("\n罗马不是一天建成的, 继续保持哦:)\n");
17     else
18         printf("\n罗马不是一天毁灭的, 我们来建设吧\n");
19     system("pause");
20     return 0;
21 }

实验截图

image

 

image

image

 

image

实验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);
16     printf("x = %f, y = %lf\n",x, y);
17     system("pause");
18     return 0;
19 }

实验截图

image

 

实验5

源代码:

 1 // 计算10亿秒约等于多少年,并打印输出
 2 #include <stdio.h>
 3 #include<stdlib.h>
 4 int main() 
 5 {
 6     int year;
 7     year=(1e+9)/(365*24*60*60);
 8     printf("10亿秒约等于%d年\n", year);
 9     system("pause");
10     return 0;
11 }

实验截图

image

 

实验6

源代码:

#include <stdio.h>
#include<stdlib.h>
#include<math.h>
int main() 
{
    double x,ans;
    while(scanf("%lf",&x)!=EOF)
    {
        ans=pow(x,365);
        printf("%.2f的365次方:%.2f\n",x,ans);
        printf("\n");
    }


    return 0;
}

实验截图:

image

 

实验7

源代码:

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

 

实验截图:

image

实验8

源代码:

 1 #include <stdio.h>
 2 #include<math.h>
 3 int main() 
 4 {
 5     int a,b,c;
 6     double area,s,m;
 7     while(scanf("%d%d%d",&a,&b,&c)!=EOF)
 8     {
 9     s=(a+b+c)/2.0;
10     area=sqrt(s*(s-a)*(s-b)*(s-c));
11     printf("a=%d,b=%d,c=%d,area=%.3f",a,b,c,area);
12     }
13     return 0;
14 }

 

实验截图:

posted @ 2026-03-19 20:47  zhangqingyang347  阅读(24)  评论(0)    收藏  举报