task1 code
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 #define N 5 5 #define N1 374 6 #define N2 465 7 int main() 8 { 9 int number; 10 int i; 11 srand(time(0)); // 以当前系统时间作为随机种子 12 for (i = 0; i < N; ++i) { 13 number = rand() % (N2 - N1 + 1) + N1;// 14 printf("202383290376%04d\n", number); 15 } 16 return 0; 17 }
task1 result
Q1:生成一个374-465之间的随机数。
Q2:在学号后面随机生成随机数
task2 code
1 int main() { 2 char ch; 3 4 while (scanf("%c", &ch) != EOF) { 5 if (ch >= 'a' && ch <= 'z') { 6 if (ch == 'r') 7 printf("stop!\n"); 8 else if (ch == 'g') 9 printf("go go go\n"); 10 else if (ch == 'y') 11 printf("wait a minute\n"); 12 else 13 printf("something must be wrong\n"); 14 } 15 } 16 17 return 0; 18 }
task2 result
task3 code
1 #include<stdio.h> 2 #include<stdlib.h> 3 #define F_DAY 1 4 #define L_DAY 30 5 int main() { 6 int day; 7 int i; 8 int n; 9 10 srand(time(0)); 11 day = rand() % (L_DAY - F_DAY + 1) + F_DAY; 12 printf("猜猜2023年11月哪一天会是你的lucky day\n"); 13 printf("开始喽,你有三次机会,猜吧(1~30): \n"); 14 for (i = 0; i < 3; i++) { 15 scanf("%d", &n); 16 if (n < day) { 17 printf("猜早了\n再猜(1~30): \n"); 18 } 19 else if (n == day) { 20 printf("猜中了!\n"); 21 break; 22 } 23 else { 24 printf("猜晚了\n再猜(1~30): \n"); 25 } 26 } 27 printf("次数用完啦,你的lucky day是%d", day); 28 29 return 0; 30 }
task3 result
task4 code
1 #include<stdio.h> 2 int main() { 3 int n, a; 4 double s = 0; 5 double i; 6 7 while (scanf("%d%d", &n, &a) != EOF) { 8 int j = 1; 9 double sum = 0; 10 for (i = 1; i <= n; i++) { 11 s = i / (a * j); 12 sum += s; 13 j = j * 10 + 1; 14 } 15 printf("n = %d, a = %d, s = %lf\n", n, a, sum); 16 } 17 18 return 0; 19 }
task4 result
task5 code
1 #include<stdio.h> 2 int main() { 3 int l, c; 4 5 for (l = 1; l <= 9; l++) { 6 for (c = 1; c <= l; c++) { 7 printf("%d*%d = %2d ", l, c, l * c); 8 } 9 printf("\n"); 10 } 11 return 0; 12 }
task5 result
task6 code
1 #include<stdio.h> 2 int main() { 3 int n, i, t = 0, j = 0; 4 5 printf("input n: "); 6 scanf("%d", &n); 7 8 for (; n > 0; n--) { 9 10 for (t = 0; t < j; t++) { 11 printf("\t"); 12 } 13 14 for (i = 1; i <= 2 * n - 1; i++) { 15 printf("\t 0 "); 16 } 17 printf("\n"); 18 19 for (t = 0; t < j; t++) { 20 printf("\t"); 21 } 22 23 for (i = 1; i <= 2 * n - 1; i++) { 24 printf("\t<H>"); 25 } 26 printf("\n"); 27 28 for (t = 0; t < j; t++) { 29 printf("\t"); 30 } 31 32 for (i = 1; i <= 2 * n - 1; i++) { 33 printf("\tI I"); 34 } 35 printf("\n"); 36 37 j += 1; 38 } 39 40 return 0; 41 }
task6 result
标签:main,code,int,实验,printf,include,day From: https://www.cnblogs.com/nuist0415/p/17767910.html