标签:main 思考 随机 ++ rgba 系统时间 考题 clu return
实验任务一:
// 生成N个0~99之间的随机整数,并打印输出 #include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 int main() { int x, n; srand(time(0)); // 以当前系统时间作为随机种子 for(n=1; n<=N; n++) { x = rand() % 100; // 生成一个0~99之间的随机整数 printf("%3d", x); } printf("\n"); return 0; }
思考题
// 生成N个0~31之间的随机整数,并打印输出 #include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 int main() { int x, n; srand(time(0)); // 以当前系统时间作为随机种子 for(n=1; n<=N; n++) { x = rand() % 31+1; // 生成一个1~31之间的随机整数 printf("%3d", x); } printf("\n"); return 0; }
实验任务二:
#include<stdio.h> #include<stdlib.h> #include<time.h> #define N 3 int main(){ int x,n,a; srand(time(0)); x = rand()%31+1; printf("猜猜2021年5月哪一天会是你的lucky day\n开始喽,你有三次机会,猜吧(1~31):"); for(n=1;n<=N;n++){ scanf("%d",&a); if(a>x) { if(n<3) printf("你猜的日期晚了,lucky day悄悄溜到前面了\n再猜(1~31):"); else printf("你猜的日期晚了,lucky day已经过了\n"); } else if(a<x) { if(n<3) printf("你猜的日期早了,lucky day悄悄溜到后面了\n再猜(1~31):"); else printf("你猜的日期早了,lucky day还没到呢\n"); } else {printf("恭喜你猜对了!\n");break;} } printf("次数已经用完了很遗憾你没有猜对。偷偷告诉你:5月,你的lucky day是%d号\n",x); return 0; }
实验任务三:
标签:main 思考 随机 ++ rgba 系统时间 考题 clu return
原文地址:https://www.cnblogs.com/wyzyf/p/14655550.html