task1
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;}View Code
1.在374~465之间随机数字
2.随机抽取学生学号
task2
1 #include<stdio.h> 2 int main(){ 3 char n; 4 while(scanf("%c",&n)!=EOF){ 5 getchar(); 6 switch(n){ 7 case 'r' :printf("stop!\n");break; 8 case 'y' :printf("wait a minute\n");break; 9 case 'g' :printf("go go go\n");break; 10 default :printf("something must be wrong...\n");break; 11 } 12 } 13 return 0; 14 }View Code
task3
1 #include<stdio.h> 2 #include<time.h> 3 #include<stdlib.h> 4 #define N 4 5 #define N1 1 6 #define N2 30 7 int main(){ 8 int number,count=0,n; 9 printf("猜猜2023年11月哪天会是你的lucky day吧~\n"); 10 printf("开始吧,你有三次机会~(1~30)\n"); 11 srand(time(0) ); 12 number=rand()%(N2-N1+1)+N1; 13 if(n==number) 14 printf("哇,猜中了!"); 15 while(scanf("%d",&n)!=EOF){ 16 if(n<number) 17 printf("你的日期猜早了,你的lucky day还没到呢\n再猜:"); 18 if(n>number) 19 printf("你的日期猜晚了,你的lucky day已经过了\n再猜:"); 20 ++count; 21 if(count==3){ 22 printf("次数用完啦,答案是:%d",number);break; 23 } 24 } 25 return 0; 26 }View Code
task4
1 #include<stdio.h> 2 int main(){ 3 int n,a,i,t=0; 4 double sum=0; 5 while(scanf("%d%d",&n,&a)!=EOF){ 6 for(i=1;i<=n;i++){ 7 t=t*10+a; 8 sum=1.0*i/t+sum; 9 } 10 printf("n=%d,a=%d,s=%lf",n,a,sum); 11 } 12 }View Code
task5
1 #include<stdio.h> 2 int main(){ 3 int a,b; 4 for(a=1;a<=9;a++){ 5 for(b=1;b<=a;b++) 6 printf("%d*%d=%d\t",a,b,a*b); 7 printf("\n"); 8 } 9 return 0; 10 }View Code
task6
1 #include<stdio.h> 2 int main(){ 3 int n,a,b,s,m; 4 printf("请输入n:"); 5 scanf("%d",&n); 6 m=n; 7 for(;n>0;n--){ 8 for(s=n;s<m;s++) 9 printf("\t"); 10 for(a=2*n-1;a>0;a--){ 11 printf(" O \t"); 12 } 13 printf("\n"); 14 for(s=n;s<m;s++) 15 printf("\t"); 16 for(a=2*n-1;a>0;a--){ 17 printf("<H>\t"); 18 } 19 printf("\n"); 20 for(s=n;s<m;s++) 21 printf("\t"); 22 for(a=2*n-1;a>0;a--){ 23 printf("I I\t"); 24 } 25 printf("\n"); 26 } 27 return 0; 28 }View Code
标签:Code,int,number,实验,printf,include,define From: https://www.cnblogs.com/zjl-love-wsx/p/17769308.html