实验1
task1_1.c
1 #include <stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 printf(" 0 \n"); 6 printf("<H>\n"); 7 printf("I I\n"); 8 printf(" 0 \n"); 9 printf("<H>\n"); 10 printf("I I\n"); 11 12 system("pause"); 13 14 return 0; 15 }

task1_2.c
1 #include <stdio.h> 2 #include <stdlib.h> 3 int main() 4 { 5 printf(" o o \n"); 6 printf("<H> <H>\n"); 7 printf("I I I I\n"); 8 9 system("pause"); 10 11 return 0; 12 }

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 }



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' || ans1 == 'Y') && (ans2 == 'y' || ans2 == 'Y')) 16 printf("\n罗马不是一天建成的,继续保持哦:)\n"); 17 else 18 printf("\n罗马不是一天毁灭的,我们来建设吧\n"); 19 20 system("pause"); 21 22 return 0; 23 24 }






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 }

task5.c
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() 5 { 6 int year; 7 8 year = (int)(1000000000/(60*60*24*365)+0.5); 9 10 printf("10亿秒约等于%d年\n", year); 11 12 system("pause"); 13 14 return 0; 15 }

task6_2
1 #include <stdio.h> 2 #include <math.h> 3 #include <stdlib.h> 4 5 int main() 6 7 { 8 double x, ans; 9 10 while(scanf("%lf", &x) != EOF) 11 { 12 ans = pow(x, 365); 13 printf("%.2f的365次方: %.2f\n", x, ans); 14 printf("\n"); 15 } 16 17 system("pause"); 18 19 return 0; 20 }

task7.c
1 #include <stdio.h> 2 #include <math.h> 3 #include <stdlib.h> 4 5 int main() 6 { 7 double celsius; 8 double fahrenheit; 9 10 while(scanf("%lf", &celsius)) 11 { 12 fahrenheit = (9.0/5.0) * celsius + 32; 13 printf("摄氏度c = %.2f时, 华氏度f = %.2f\n", celsius, fahrenheit); 14 printf("\n"); 15 } 16 system("pause"); 17 return 0; 18 }

task8.c
1 #include <stdio.h> 2 #include <math.h> 3 #include <stdlib.h> 4 5 int main() 6 { 7 double a, b, c; 8 double s, area; 9 10 while(scanf("%lf%lf%lf", &a, &b, &c) == 3) 11 { 12 s = (a + b + c)/2; 13 14 area = sqrt(s * (s - a) * (s - b) * (s - c)); 15 16 printf("a = %f, b = %f, c = %f, area = %.3f\n", a, b, c, area); 17 printf("\n"); 18 19 } 20 system("pause"); 21 return 0; 22 }

浙公网安备 33010602011771号