task1_1 源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main(void) 4 { 5 printf(" 0 \n"); 6 printf("<H>\n"); 7 printf("| |\n"); 8 printf(" 0 \n"); 9 printf("<H>\n"); 10 printf("| |\n"); 11 system("pause"); 12 13 return 0; 14 }
task1_1 运行结果·
task1_2 源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main(void) 4 { 5 int ct; 6 7 for (ct = 0; ct <= 1; ct++) 8 printf("\t 0 "); 9 printf("\n"); 10 for (ct = 0; ct <= 1; ct++) 11 printf("\t<H>"); 12 printf("\n"); 13 for (ct = 0; ct <= 1; ct++) 14 printf("\t| |"); 15 printf("\n"); 16 system("pause"); 17 18 return 0; 19 }
task1_2 运行结果
task2 源代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 float a, b, c; 6 7 scanf("%f%f%f", &a, &b, &c); 8 if(a + b >c && a + c > b && b + c > a) 9 printf("能构成三角形\n"); 10 else 11 printf("不能构成三角形\n"); 12 system("pause"); 13 14 return 0; 15 }
task2 运行结果
task3 源代码
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(); // 从键盘输入一个字符,赋值给ans1 9 getchar(); // 思考这里为什么要加这一行。试着去掉这一行,看看对运行有没有影响。 10 printf("\n动手敲代码实践了没? (输入y或Y表示敲了,输入n或N表示木有敲): "); 11 ans2 = getchar(); 12 if (ans1 == 'y' && ans2 == 'y' || ans1 == 'Y' && ans2 == 'Y' || ans1 == 'Y' && ans2 == 'y' || ans1 == 'y' && ans2 == 'Y') 13 printf("\n罗马不是一天建成的, 继续保持哦:)\n"); 14 else 15 printf("\n罗马不是一天毁灭的, 我们来建设吧\n"); 16 system("pause"); 17 18 return 0; 19 }
task3 运行结果
task3 问题
getchar();用来获取输入的【Enter】。如果没有的话,必定执行else分支。
task4 源代码
1 #define _CRT_SECURE_NO_WARNINGS 2 #include<stdio.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); //这里只能用%lf因为是double类型 16 printf("x = %f, y = %f\n", x, y); 17 18 return 0; 19 }
task4 结果
task5 源代码
1 #include <stdio.h> 2 int main() 3 { 4 int year; 5 6 year = 1.0e9 / 3600 / 24 / 365; 7 printf("10亿秒约等于%d年\n", year); 8 9 return 0; 10 }
task5 运行结果
task6 源代码
1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 #include <math.h> 4 int main() 5 { 6 double x, ans; 7 8 while (scanf("%lf", &x) != EOF) 9 { 10 ans = pow(x, 365); 11 12 printf("%.2f的365次方: %.2f\n", x, ans); 13 printf("\n"); 14 } 15 16 return 0; 17 }
task6 运行结果
task7 源代码
1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 int main() 4 { 5 double C, F; 6 7 while (scanf("%lf", &C) != EOF) 8 { 9 F = 9 * C / 5 + 32; 10 printf("摄氏度c = %.2f时,华氏度f = %.2f\n", C, F); 11 } 12 13 return 0; 14 }
task7 运行结果
task8 源代码
1 #define _CRT_SECURE_NO_WARNINGS 2 #include<stdio.h> 3 #include<math.h> 4 int main(void) 5 { 6 double a, b, c; 7 double s; 8 double ans; 9 10 printf("Enter side lengths of triangle:\n"); 11 while (scanf("%lf%lf%lf", &a, &b, &c) != EOF) 12 { 13 if (a + b <= c || b + c <= a || a + c <= b) 14 { 15 printf("It isn't a triangle! ~_~"); 16 break; 17 } 18 19 s = (a + b + c) / 2; 20 ans = sqrt(s * (s - a) * (s - b) * (s - c)); 21 printf("ans = %.3f\n", ans); 22 } 23 24 return 0; 25 }
task8 运行结果