实验任务1
#include<stdio.h> #include<stdlib.h> #include<time.h> #define N 5 int main() { int number; int i; srand(time(0)); for(i=0;i<N;++i);{ number=rand()%500+1; printf("20228329%04d\n", number); } system("pause"); return 0; }
问题一:随机产生1~500间的一个随机数
问题二:随机打印2022年新生的学号
实验任务2
#include<stdio.h> #include<stdlib.h> #include<time.h> #define N 3 int main() { printf("猜猜2022年11月哪一天会是你的lucky day\n"); printf("开始喽,你有三次机会,猜吧(1~30):"); int day; int num; int i; srand(time(0)); for (i = 0; i < N; ++i) { num = rand() % 30 + 1; scanf_s("%d", &day); if (day == num) { printf("哇,猜中了"); break; } else if (day < num) { printf("你猜的日期早了,你的lucky day还没到呢,再猜(1~30)"); } else(day > num); { printf("你猜的日期晚了,你的lucky day已经过啦,再猜(1~30)"); } } system("pause"); return 0; }
实验任务3
#include<stdio.h> #include<stdlib.h> int main() { char color; printf("请输入交通信号灯颜色,r表示red,g表示green,y表示yellow\n"); while (scanf_s("%c", &color) != EOF) { getchar(); switch (color) { case'r':printf("stop\n"); break; case'g':printf("go go go\n"); break; case'y':printf("wait a minute\n"); break; default:printf("something must be wrong...\n"); break; } } system("pause"); return 0; }
实验任务4
#include<stdio.h> #include<stdlib.h> int main() { int n, a, i; double s, b, c; while (scanf_s("%d%d", &n, &a) != EOF) { b = 1; c = a; for (s = 0, i = 1; i <= n;++i) { s = s + b / c; b = b + 1; c = c * 10 + a; } printf("n=%d,a=%d,s=%.6f\n", n, a, s); } system("pause"); return 0; }
实验任务5
#include<stdio.h> #include<stdlib.h> int main() { int a, b; for (a = 1; a <= 9; ++a) { for (b = 1; b <= a; ++b) printf("%d*%d=%2d ", b, a, a * b); printf("\n"); } system("pause"); return 0; }
实验任务6
#include<stdio.h> #include<stdlib.h> int main() { int n, a, b, c; printf("input:"); scanf_s("%d", &n); for (b = 0; b < n; b++) { for (c = 0; c < b; c++) printf("\t"); for (a = 0; a < 2 * (n - b) - 1; a++) printf(" O \t"); printf("\n"); for (c = 0; c < b; c++) printf("\t"); for (a = 0; a < 2 * (n - b) - 1; a++) printf("<H>\t"); printf("\n"); for (c = 0; c < b; c++) printf("\t"); for (a = 0; a < 2 * (n - b) - 1; a++) printf("I I\t"); printf("\n"); } system("pause"); return 0; }
标签:include,int,num,实验,printf,main,day From: https://www.cnblogs.com/lqq0727/p/16807094.html