task1
1.源代码
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 system("pause"); 9 return 0; 10 }
2.运行结果
task1-1
1.源代码
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 system("pause"); 12 return 0; 13 }
2.运行结果
task1-2
1.源代码
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 system("pause"); 9 return 0; 10 }
2.运行结果
task 2
1.源代码
1 #include <stdio.h> 2 #include <stdlib.h> 3 int main() 4 { 5 int a, b, c; 6 scanf("%d%d%d", &a, &b, &c); 7 if (a + b > c && a + c > b && b + c > a) 8 printf("能构成三角形\n"); 9 else 10 printf("不能构成三角形\n"); 11 system("pause"); 12 return 0; 13 }
2.运行结果
task3(注:此实验源代码可与task8结合)
1.源代码
1 #include <stdio.h> 2 #include <stdlib.h> 3 int main() 4 { 5 char ans1, ans2; 6 printf("每次课前认真预习、课后及时复习了没? (输入y或Y表示有,输入n或N表示没有) :"); 7 ans1 = getchar(); 8 getchar(); 9 printf("\n动手敲代码实践了没? (输入y或Y表示敲了,输入n或N表示木有敲) : "); 10 ans2 = getchar(); 11 if ((ans1 == 'Y' && ans2 == 'Y') ||(ans2 == 'y' && ans1 == 'y') ||(ans1 == 'Y' && ans2 == 'y') ||(ans1 == 'y' && ans2 == 'Y'))// 待补足,判断用户回答ans1和ans2都是小写y或大写Y 12 printf("\n罗马不是一天建成的, 继续保持哦:)\n"); 13 else 14 printf("\n罗马不是一天毁灭的, 我们来建设吧\n"); 15 16 system("pause"); 17 return 0; 18 }
2.运行结果
3.思考
line8作用是录入ans2的值,若删除,则无法输入ans2值
task4
1.源代码
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 = %lf, y = %lf\n", x, y); 17 system("pause"); 18 return 0; 19 }
2.运行结果
task.5
1.源代码
1 #include <stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int year; 6 7 double second = 1e9; 8 double t = ((second / 3600) / 24) / 365; 9 if (t - (int)t < 0.5) { 10 year = (int)t; 11 } 12 else { 13 year = (int)t + 1; 14 } 15 printf("10亿秒约等于%d年\n", year); 16 system("pause"); 17 return 0; 18 }
2.运行结果
task6-1
1.源代码
1 #include <stdio.h> 2 #include <math.h> 3 #include<stdlib.h> 4 int main() 5 { 6 double x, ans; 7 scanf("%lf", &x); 8 ans = pow(x, 365); 9 printf("%.2f的365次方: %.2f\n", x, ans); 10 system("pause"); 11 return 0; 12 }
2.运行结果
task.6-2
1.源代码
1 #include <stdio.h> 2 #include <math.h> 3 #include<stdlib.h> 4 int main() 5 { 6 double x, ans; 7 while (scanf("%lf", &x) != EOF){ 8 ans = pow(x, 365); 9 printf("%.2f的365次方: %.2f\n", x, ans); 10 system("pause");} 11 return 0; 12 }
2.运行结果
task.7
1.源代码
1 #include <stdio.h> 2 #include <math.h> 3 #include<stdlib.h> 4 int main() 5 { 6 double f; 7 double c; 8 printf("请输入摄氏度数:"); 9 while (scanf("%lf", &c) != EOF) { 10 f = 9.0 / 5.0 * c + 32.0; 11 printf("华氏度f = %.2lf\n",f); 12 printf("\n"); 13 system("pause"); 14 } 15 return 0; 16 }
2.运行结果
task.8
1.源代码
1 #include <stdio.h> 2 #include <math.h> 3 #include<stdlib.h> 4 int main() 5 { 6 double a, b, c; 7 double s; 8 double area; 9 while (scanf("%lf %lf %lf", &a, &b, &c) != EOF) { 10 if (a + b > c && a + c > b && b + c > a){ 11 12 s = (a + b + c) / 2; 13 area = sqrt(s * (s - a) * (s - b) * (s - c)); 14 printf("a = %d, b = %d, c = %d, area = %.3lf\n", (int)a, (int)b, (int)c, area); 15 printf("\n"); 16 } 17 else 18 printf("不能构成三角形\n");} 19 return 0; 20 }
2.运行结果
实验总结:可以将task3与task8结合,先判断是否能构成三角形,若能,才计算面积
标签:10,源代码,int,实验,printf,main,include From: https://www.cnblogs.com/JUVBUFFON/p/17738724.html