task1_1
#include<stdio.h> int main() { printf(" O \n"); printf("<H>\n"); printf("I I\n"); printf(" O \n"); printf("<H>\n"); printf("I I\n"); return 0; }
task1_2
#include<stdio.h> int main() { printf(" O O\n"); printf("<H> <H>\n"); printf("I I I I\n"); return 0; }
task2_2
#include<stdio.h> #include<math.h> int main() { double x, ans; while (scanf_s("%lf", &x) != EOF) { ans = pow(x, 365); printf("%.2f的365次方:%.2f\n", x, ans); printf("\n"); } return 0; }
task2_3
#include<stdio.h> #include<math.h> int main() { double c, f; while (scanf_s("%lf", &c)!=EOF) { f = 9 * c / 5 + 32; printf("摄氏度c=%.2f时,华氏度f=%.2f", c, f); printf("\n"); printf("\n"); } return 0; }
实验任务3
#include<stdio.h> #include<math.h> int main() { double i, n, sum=0,b; i = 0; scanf_s("%lf", &n); while (i <= n) { b = pow(2, i); sum = sum + b; i++; } printf("sum=%f\n", sum); system("pause"); return 0; }
不能运行的原因:sum被分配的内存空间无法容纳n=63时sum的值,造成数值溢出。
实验任务4
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> int main() { double x, y; char c1, c2, c3; int a1, a2, a3; scanf("%d,%d,%d", &a1, &a2, &a3);/*缺少变量地址*/ printf("a1=%d,a2=%d,a3=%d\n", a1, a2, a3); getchar();/*缺少此函数*/ scanf("%c,%c,%c", &c1, &c2, &c3); printf("c1=%c, c2=%c, c3=%c\n",c1, c2, c3); getchar();/*缺少此函数*/ scanf("%lf,%lf", &x, &y); printf("x=%lf,y=%lf\n",x, y); return 0; }
实验任务5
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> int main() { int age1, age2; char gender1, gender2; scanf(" %d%c%d%c", &age1, &gender1, &age2, &gender2); printf("age1=%d,gender1=%c\n", age1, gender1); printf("age2=%d,gender2=%c\n", age2, gender2); return 0; }
实验任务6
#include<stdio.h> int main() { char ans1, ans2; printf("每次课前认真预习、课后及时复习了没?(输入y或Y表示有,输入n或N表示没有)"); ans1 = getchar(); getchar(); printf("\n动手敲代码了没?(输入y或Y表示有,输入n或N表示没有): "); ans2 = getchar(); if ((ans1 == 'y' || ans1 == 'Y') && (ans2 == 'y' || ans2 == 'Y')) { printf("罗马不是一天建成的,继续保持哦\n"); } else { printf("罗马不是一天毁灭的,我们来建设吧\n"); } return 0; }
实验任务7
#include<stdio.h> int main() { int answer; char words[5000]; printf("网课学习让一些人欢喜一些人忧.\n"); printf("1.作为喜欢自学且自律的人,觉得这样很好,有网络,自主学习,很OK.\n"); printf("2.不喜,不喜,很不喜,眼睛快瞎了,脑壳有点卡...\n"); printf("3.中间派.不知道.说不清.\n"); printf("4.其他...\n"); printf("你的选择: "); scanf_s("%d", &answer); if (answer == 4) { printf("请补充你的想法:\n"); getchar(); gets(words); } printf("\n"); printf("当遇到问题时,你会选择:\n"); printf("1.遇到问题,就解决问题。不懂得,搜索式学习,逐个攻破.\n"); printf("2.遇到问题,不高兴。然后....没有了.\n"); printf("3.其他...\n"); printf("你的选择:"); scanf_s("%d", &answer); if (answer == 1) printf(":)\n"); else if (answer == 2) printf("这样不能解决问题啊...我们选择1好不好:)\n"); else if (answer == 3) { printf("请补充说明你的想法:\n"); getchar(); gets(words); } return 0; }
标签:include,return,int,scanf,实验,printf,main From: https://www.cnblogs.com/tyl0131/p/16786422.html