实验1 2026.10.16

 

四,实验结论 

task1

源代码

#include <stdio.h>

int main()
{
printf(" o   o\n");
printf("<H> <H>\n");
printf("I I I I\n");

return 0;
}

运行截图

image

 

646549e924351dfe3f142130567d5cb6

cbafcd8bd53809ab16a78ae838b5d863

 

049ac37edfb2743f1d03baecc85c2733

 

  

 

task2

源代码

#include <stdio.h>

int main()
{
double a, b, c;

// 输入三边边长
scanf("%lf%lf%lf", &a, &b, &c);

// 判断能否构成三角形
// 补足括号里的逻辑表达式
if(a+b>c&&b+c>a&&a+c>b)
printf("能构成三角形\n");
else
printf("不能构成三角形\n");

return 0;
}

运行截图

267cbebd6f67ca88a4f140bb00fdfb00

 

 

 task3

源代码

#include <stdio.h>
int main()
{
char ans1, ans2; // 保存用户输入的答案

printf("每次课及时预习/复习了没? (是-输入y或Y, 否-输入n或N) : ");
ans1 = getchar(); // 从键盘输入一个字符,赋值给ans1

getchar();// 去掉这一行,重新编译运行,观察是否影响程序结果

printf("\n动手敲代码实践了没? (是-输入y或Y, 否-输入n或N) : ");
ans2 = getchar();

if( (ans1 == 'y' || ans1 == 'Y') && (ans2 == 'y' || ans2 == 'Y') ) // 待补足,判断ans1和ans2都是y(大小写均可)
printf("\n罗马不是一天建成的, 继续保持哦:)\n");
else
printf("\n罗马不是一天毁灭的, 我们来建设吧\n");

return 0;
}

运行截图

41a8a3b3fa3c36fe48e959f0133a601d

 

38521d36b438d770c8a43b835113bfc2

 回答问题

删除后影响程序结果,getchar将输入的回车当作ans的答案。

 

task3

源代码

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

int main()
{
int year;

year = round(1000000000.0 / 365 / 24 / 60 / 60);

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

运行截图

722fe3ee330c9f0a2d046fb17072461c

 

 

task4

源代码

// 摄氏温度转换成华氏温度

#include <stdio.h>

int main() {
double c, f;

scanf("%lf", &c);

f = c * 9 / 5 + 32;

printf("摄氏度c = %.2f时, 华氏温度f = %.2f\n\n", c, f);

return 0;
}

运行截图

4576512bbffae3ec0340c6072954b12b

 

bfe35c42dd2dd7f8eb99c391c2d761f8

 

 

task5

源代码

#include <stdio.h>
#include <math.h>

int main()
{
double a, b, c, area, s;
scanf("%lf%lf%lf",&a, &b, &c);
s = (a + b + c) / 2.0;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("%.3f\n",area);
return 0;
}

运行截图

2430c722f0b505113a8f283dff386714

 

25b45471f811f6c68d74d8f4b0f8ad90

 

 

五.实验总结

 任务1中水平方向打印不会处理

posted @ 2026-10-16 17:06  lzq_4to4  阅读(4)  评论(0)    收藏  举报