#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); } return 0; }
生产一个1~500之间的随机数 程序可以随机生成学号 任务1
任务2
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int num, lnum, i; printf("猜猜2022年11月那一天会是你的lucky day\n"); printf("开始喽,你有三次机会,猜吧(1~30): "); srand(time(0)); for (i = 1; i <= 3; i++) { scanf_s("%d", &num); lnum = rand() % 30 + 1; if (num == lnum) { printf("哇,猜对了\n"); break; } else if (num < lnum) { printf("你猜的日期早了,你的lucky day 还没到呢\n"); printf("再猜:"); } else { printf("你猜的日期晚了,你的lucky day还没到呢\n"); printf("再猜:"); } } if (i == 4) printf("次数用完了,偷偷告诉你:11月你的lucky day是%d号\n", lnum); return 0; }
任务3
#include<stdio.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; } } return 0; }
任务4
#include<stdio.h> #include<math.h> int main() { int n, i,a,j,c; float s; while (scanf_s("%d %d", &n, &a) != EOF) { s = 0; for (i = 1; i <= n; i++) { c = a; for (j = 2; j <= i; j++) c = c + c * pow(10, j - 1); s = s + (float)i / c; } printf("n = %d,a = %d,s = %lf\n", n,a,s); } return 0; }
任务5
#include<stdio.h> int main() { int i, j; for (i = 1; i <= 9; i++) { for (j = 1; j <= i; j++) printf("%d * %d = %d\t", j, i, j * i); printf("\n"); } return 0; }
任务6
#include<stdio.h> int main() { int i, j, n, s, k,q,r,t,p; scanf_s("%d", &n); s = n; for (i = 1; i <= n; i++) { for (j = 1; j < i; j++) printf("\t"); for (k = 1; k <= (2 * s - 1); k++) printf(" o \t"); printf("\n"); for (q = 1; q < i; q++) printf("\t"); for (r = 1; r <= (2 * s - 1); r++) printf("<H>\t"); printf("\n"); for (t = 1; t < i; t++) printf("\t"); for (p = 1; p <= (2 * s - 1); p++) printf("I I\t"); printf("\n"); s = s - 1; } return 0; }
标签:include,int,number,break,实验,printf,main From: https://www.cnblogs.com/hffhff/p/16804594.html