实验1
task1.1c
1 #include<stdio.h> 2 int main() 3 { 4 printf(" O\n"); 5 printf("<H>\n"); 6 printf("I I\n"); 7 printf(" O\n"); 8 printf("<H>\n"); 9 printf("I I\n"); 10 return 0; 11 }
task1.2c
1 #include<stdio.h> 2 int main() 3 { 4 printf(" O"); 5 printf(" O\n"); 6 printf("<H>"); 7 printf("<H>\n"); 8 printf("I I"); 9 printf("I I\n"); 10 return 0; 11 }
task2c
1 #include<stdio.h> 2 int main() 3 { 4 double a, b, c; 5 scanf("%lf%lf%lf",&a,&b,&c); 6 if(a+b>c&&a+c>b&&b+c>a) 7 printf("能构成三角形\n"); 8 else 9 printf("不能构成三角形\n"); 10 11 return 0; 12 }
task3c
1 #include<stdio.h> 2 int main() 3 { 4 char ans1,ans2; 5 printf("每次课前认真预习、课后及时复习了没? (输入y或Y表示有,输入n或N表示没有) :"); 6 ans1 = getchar(); 7 getchar(); 8 printf("\n动手敲代码实践了没? (输入y或Y表示敲了,输入n或N表示木有敲) :"); 9 ans2 = getchar(); 10 if((ans1 == 'y'||ans1 == 'Y')&&(ans2 == 'y'||ans2 == 'Y')) 11 printf("\n罗马不是一天建成的, 继续保持哦:)\n"); 12 else 13 printf("\n罗马不是一天毁灭的, 我们来建设吧\n"); 14 15 return 0; 16 }
getchar()是为了读取回车键字符(\n)
task4c
1 #include<stdio.h> 2 int main() 3 { 4 double x, y; 5 char c1, c2, c3; 6 int a1 ,a2, a3; 7 8 scanf("%d%d%d",&a1,&a2,&a3); //输入数据时在变量前应该加上定位符& 9 printf("a1 = %d,a2 = %d,a3 = %d\n",a1,a2,a3); 10 11 scanf(" %c%c%c",&c1,&c2,&c3); 12 printf("c1 = %c,c2 = %c,c3 = %c\n",c1,c2,c3); 13 14 scanf("%lf%lf",&x,&y); //double在输入时必须使用lf 15 printf("x = %lf,y = %lf",x,y); 16 return 0; 17 }
task5c
1 #include<stdio.h> 2 int main() 3 { 4 int year; 5 float m; 6 m = 1e9; 7 year = m/(60*60*24*365); 8 printf("10亿秒约等于%d年\n",year); 9 return 0; 10 }
task6c
1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 double x,ans; 6 while(scanf("%lf",&x) != EOF) 7 { 8 ans = pow(x,365); 9 printf("%.2f的365次方:%.2f\n",x,ans); 10 printf("\n"); 11 } 12 13 return 0; 14 }
task7c
1 #include<stdio.h> 2 3 int main() 4 { 5 double C; 6 while(scanf("%lf",&C) != EOF) 7 { 8 double F; 9 F = 1.8*C + 32; 10 printf("摄氏度c = %.2lf时,华氏度f = %.2lf\n",C,F); 11 printf("\n"); 12 } 13 14 return 0; 15 }
task8c
1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 double a,b,c; 6 while(scanf("%lf%lf%lf",&a,&b,&c) != EOF) 7 { 8 double s; 9 s = (a+b+c)/2; 10 11 double S; 12 S = sqrt(s*(s-a)*(s-b)*(s-c)); 13 14 printf("a = %.0lf,b = %.0lf,c = %.0lf,area = %.3lf\n",a,b,c,S); 15 printf("\n"); 16 } 17 18 return 0; 19 }