实验1
实验任务1
task1_1.c源代码:
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 12 system("pause"); 13 return 0; 14 }
测试截图:
task1_2.c源代码:
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int main() 5 { 6 printf(" O O\n"); 7 printf("<H> <H>\n"); 8 printf("I I I I\n"); 9 10 system("pause"); 11 12 return 0; 13 }
测试截图:
实验任务2
task2.c源代码:
1 #include <stdio.h> 2 #include <stdlib.h> 3 int main() 4 { 5 double a,b,c; 6 7 scanf("%lf%lf%lf",&a,&b,&c); 8 9 if(a+b>c&&a+c>b&&b+c>a) 10 printf("能构成三角形\n"); 11 else 12 printf("不能构成三角形\n"); 13 14 system("pause"); 15 16 return 0; 17 }
测试截图:
实验任务3
task3.c源代码:
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(); 9 10 getchar(); 11 12 printf("\n动手敲代码实践了没? (输入y或Y表示敲了,输入n或N表示木有敲) : "); 13 ans2=getchar(); 14 15 if((ans1=='y'&&ans2=='y')||(ans1=='Y'&&ans2=='Y')) 16 printf("\n罗马不是一天建成的, 继续保持哦:)\n"); 17 else 18 printf("\n罗马不是一天毁灭的, 我们来建设吧\n"); 19 20 system("pause"); 21 22 return 0; 23 }
测试截图:
问题:1.t跳过第二个问题直接显示最后的结果
2.getchar()提示下一次输入
实验任务4
task4.c源代码:
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 18 system("pause"); 19 20 return 0; 21 }
测试截图:
实验任务5
task5.c源代码:
1 #include <stdio.h> 2 #include <stdlib.h> 3 int main() 4 { 5 int year; 6 7 year=(int)(1000000000/(365*24*60*60)+0.5); 8 9 printf("10亿秒约等于%d年\n", year); 10 system("pause"); 11 return 0; 12 }
测试截图:
实验任务6
task6_2.c源代码:
1 #include<stdio.h> 2 #include<math.h> 3 4 int main() 5 { 6 double x,ans; 7 8 while(scanf("%lf",&x)!=EOF) 9 { 10 ans=pow(x,365); 11 printf("%.2f的365次方:%.2f\n",x,ans); 12 printf("\n"); 13 } 14 return 0; 15 }
测试截图:
实验任务7
task7.c源代码:
1 #include<stdio.h> 2 3 int main() 4 { 5 double c,f; 6 7 while(scanf("%lf",&c)!=EOF) 8 { 9 f=c*9/5+32; 10 printf("摄氏度c=%.2f时,华氏度f=%.2f",c,f); 11 printf("\n"); 12 } 13 return 0; 14 }
测试截图:
实验任务8
task8.c源代码:
1 #include<stdio.h> 2 #include<math.h> 3 4 int main() 5 { 6 int a,b,c; 7 double s,area; 8 9 while(scanf("%d%d%d",&a,&b,&c)!=EOF) 10 { 11 s=(a+b+c)/2; 12 area=sqrt(s*(s-a)*(s-b)*(s-c)); 13 printf("a=%d,b=%d,c=%d,area=%.3f",a,b,c,area); 14 printf("\n"); 15 } 16 return 0; 17 }
测试截图:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步