1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 5 #define N 5 6 7 int main() 8 { 9 int number; 10 int i; 11 12 srand(time(0)); 13 14 for(i=0;i<N;++i){ 15 number = rand()%65 +1; 16 printf("20238331%04d\n",number); 17 } 18 system("pause"); 19 return 0; 20 }
line15功能为:生成1到65的随机数
程序的功能是:生成202383310001到202383310065之间的五个随机学号
task2
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int main() 5 { 6 char color; 7 8 while(scanf_s("%c",&color)!=EOF) 9 { 10 switch(color) 11 { 12 case'r':printf("stop!\n"); 13 break; 14 case'g':printf("go go go\n"); 15 break; 16 case'y':printf("wait a minute\n"); 17 break; 18 default:printf("something must be wrong...\n"); 19 break; 20 } 21 getchar(); 22 } 23 24 system("pause"); 25 return 0; 26 }
task3
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 5 int main() 6 { 7 int lucday, a, b = 0; 8 9 srand(time(0)); 10 lucday = rand() % 31 + 1; 11 printf("猜猜2024年5月哪一天会是你的lucky day\n\n"); 12 printf("开始喽,你有三次机会,猜吧(1~31):"); 13 14 while (b < 3) 15 { 16 scanf_s("%d", &a); 17 printf("\n"); 18 19 if (a == lucday) 20 { 21 printf("哇,猜中了:-)\n"); 22 return 0; 23 } 24 else if (a < lucday) 25 { 26 printf("你猜的日期早了,你的lucky day还没到呢\n"); 27 } 28 else 29 { 30 printf("你猜的日期晚了,你的lucky day在前面哦\n"); 31 } 32 33 if (b < 2) 34 { 35 printf("\n再猜(1~31):"); 36 } 37 38 b++; 39 } 40 41 if (b == 3) 42 { 43 printf("\n\n次数用完了,偷偷告诉你,5月你的lucky day是%d号\n", lucday); 44 } 45 46 return 0; 47 }
task4
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() { 5 int n, a, j, i, k; 6 double s=0.0; 7 8 while (scanf_s("%d%d", &n, &a) != EOF) { 9 10 for (i = 1; i <= n; i++) { 11 k = 0; 12 for (j = 0; j < i; j++) { 13 k = k * 10 + a; 14 } 15 s += (double)i / k; 16 } 17 printf("n=%d,a=%d,s=%1f\n\n", n, a, s); 18 } 19 return 0; 20 }
task5
int main() { int a = 0; for (a = 1;a <= 9;a++) { int b = 0; for (b = 1;b <= i;b++) printf("%d*%d=%2d\t ", a, b, a * b); printf("\n"); } return 0; }
task6
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() { 5 int n, i, k, j; 6 printf("input n:"); 7 scanf_s("%d", &n); 8 9 for (i = 0; i < n; i++) 10 { 11 for (j = 0; j < i; j++) 12 { 13 printf("\t"); 14 } 15 for (k = 2 * (n - i) - 1; k > 0; k--) 16 { 17 printf(" O \t"); 18 } 19 printf("\n"); 20 21 for (j = 0; j < i; j++) 22 { 23 printf("\t"); 24 } 25 for (k = 2 * (n - i) - 1; k > 0; k--) { 26 printf("<H>\t"); 27 } 28 printf("\n"); 29 30 for (j = 0; j < i; j++) 31 { 32 printf("\t"); 33 } 34 for (k = 2 * (n - i) - 1; k > 0; k--) 35 { 36 printf("I I\t"); 37 } 38 printf("\n"); 39 } 40 return 0; 41 }
标签:include,int,31,lucday,实验,printf,main From: https://www.cnblogs.com/aolan0705/p/18134958