实验1
实验1.1
实验1.1源代码
#include<stdio.h> #include<stdlib.h> int main() { printf(" O O \n"); printf("<H> <H>\n"); printf("I I I I\n"); system("pause"); return 0; }
#include<stdio.h> #include<stdlib.h> int main() { printf(" O \n"); printf("<H>\n"); printf("I I\n"); printf(" O \n"); printf("<H>\n"); printf("I I\n"); system("pause"); return 0; }
实验1.1运行结果



实验1.2
实验1.2源代码
//判断能否构成三角形 #define _CRT_SECURE_NO_WARNINGS 0 #include<stdio.h> #include<stdlib.h> int main() { float a,b,c; printf("请输入三个数:"); scanf("%f%f%f",&a,&b,&c); if (a+c>=b&&a+b>=c&&b+c>=a) printf("能构成三角形"); else printf("不能构成三角形"); system("pause"); return 0; }
实验1.2运行结果

实验1.3
实验1.3源代码
#include<stdio.h> #include<stdlib.h> int main() { char ans1,ans2; printf("每次课前认真复习,课前预习了没?(输入Y或y表示有,输入N或n表示没有)"); ans1 = getchar(); getchar(); printf("动手敲代码了没有(输入Y或y表示敲了,输入N或n表示没敲)"); ans2 = getchar(); if((ans1=='Y'||ans1=='y')&&ans2=='Y'||ans2=='y') printf("罗马不是一天建成的,请继续努力哦:)\n"); else printf("罗马不是一天毁灭的,我们来建设吧\n"); system("pause"); return 0; }
实验1.3运行结果

实验1.4
实验1.4源代码
#include<stdio.h> #include<stdlib.h> int main() { double x,y; char c1,c2,c3; int a1,a2,a3; scanf("%lf,%lf",&x,&y); printf("x=%lf,y=%lf\n",x,y); getchar(); scanf("%c,%c,%c",&c1,&c2,&c3); printf("c1=%c,c2=%c,c3=%c\n",c1,c2,c3); scanf("%d,%d,%d",&a1,&a2,&a3); printf("a1=%d,a2=%d,a3=%d\n",a1,a2,a3); system("pause"); return 0; }
实验1.4运行结果

注:当少了getchar()接收回车等键时,后面输出结果会变得混乱。
实验1.5
实验1.5源代码
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int year; int time; double ans; printf("请输入时间为多少亿秒:"); scanf("%d",&time); ans = pow(time,9); year = ans/31536000+0.5; printf("该时间为%d年",year); system("pause"); return 0; }
实验1.5运行结果

实验1.6
实验1.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("x的365次方为;%.2f",ans); system("pause"); } return 0; }
实验1.6运行结果

实验1.7
实验1.7源代码
#include<stdio.h> #include<stdlib.h> int main() { double c,F; while(1) { scanf("%lf",&c); printf("摄氏温度为%.2f时,",c); F = 9*c/5+32; printf("华氏温度为%.2f",F); system("pause"); } return 0; }
实验1.7运行结果

实验1.8
实验1.8源代码
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int a,b,c; double s; double area; while(scanf("%d%d%d",&a,&b,&c)!=EOF) { printf("a=%d,b=%d,c=%d",a,b,c); s=(a+b+c)/2.0; area=sqrt((s-a)*(s-b)*(s-c)*s); printf("area=%.3f",area); system("pause"); } return 0; }
实验1.8运行结果

posted on 2023-10-05 00:54 Awayfyforever 阅读(30) 评论(0) 收藏 举报
浙公网安备 33010602011771号