实验1

任务一

  • 源代码task1_1.c
点击查看代码
#include <stdio.h>
int main() 
{
printf(" O \n");
printf("<H>\n");
printf("I I\n");
printf(" O \n");
printf("<H>\n");
printf("I I\n");
return 0;
}
  • 运行测试截图

屏幕截图 2026-10-16 184749

  • 源代码task1_2.c
点击查看代码
#include <stdio.h>
int main() 
{
printf(" O     O\n");
printf("<H>   <H>\n");
printf("I I   I I\n");
return 0;
}
+ 运行测试截图

屏幕截图 2026-10-16 190139

任务二

  • 源代码task2.c
点击查看代码
#include <stdio.h>
int main() 
{
    double a, b, c;
    scanf("%lf%lf%lf", &a, &b, &c);
    if(a+b>c&&a+c>b&&b+c>a)
        printf("能构成三角形\n");
    else
        printf("不能构成三角形\n");
    return 0;
}
+ 运行测试截图

屏幕截图 2026-10-16 190728

任务三

  • 源代码task3.c
点击查看代码
#include <stdio.h>
int main()
{
    char ans1, ans2; 
    printf("每次课及时预习/复习了没? (是-输入y或Y, 否-输入n或N) :  ");
    ans1 = getchar(); 
    getchar(); 
    printf("\n动手敲代码实践了没? (是-输入y或Y, 否-输入n或N) :  ");
    ans2 = getchar();
    if (ans1==ans2) 
        printf("\n罗马不是一天建成的, 继续保持哦:)\n");
    else
        printf("\n罗马不是一天毁灭的, 我们来建设吧\n");
    return 0;
}
+ 运行测试截图

屏幕截图 2026-10-16 191255

  • 问题回答
    当line9去掉后,ans2的赋值直接跳过,经尝试输出ans2得,当ans1=y时,ans2=121,当ans1=n时,ans2=110,两者分别对应ASCII码中y和n,因此我猜测line9的作用应该是清空上一个getchar()的结果

任务四

  • 源代码task4.c
点击查看代码
#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;
}
+ 运行测试截图

屏幕截图 2026-10-16 193554

任务五

  • 源代码task5.c
点击查看代码
#include <stdio.h>
int main() 
{
    double c, f;
    scanf("%lf", &c);
    f=(9.0/5.0)*c+32;
    
    printf("摄氏度c = %.2f时, 华氏温度f = %.2f\n\n", c, f);
    return 0;
}
+ 运行测试截图

屏幕截图 2026-10-16 195910

任务六

  • 源代码task6.c
点击查看代码
#include <stdio.h>
#include <math.h>
int main(void)
{
	double a,b,c,s,x;
	scanf("%lf%lf%lf",&a,&b,&c);
	s=(a+b+c)/2.0;
	x=sqrt(s*(s-a)*(s-b)*(s-c));
	printf("%.3f\n",x);
	return 0;
}

+ 运行测试截图

屏幕截图 2026-10-16 195817

posted @ 2026-10-16 20:02  Azure_Cyz  阅读(7)  评论(0)    收藏  举报