实验二
任务一代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 5 #define N 5 6 #define N1 374 7 #define N2 465 8 9 int main(){ 10 int number; 11 int i; 12 srand(time(0)); 13 14 for(i = 1;i < N;++i){ 15 number = rand()%(N2 - N1 + 1) + N2; 16 printf("202383290376%04d\n",number); 17 18 } 19 20 21 22 23 24 return 0; 25 }
任务一截图
任务二代码
1 #include<stdio.h> 2 int main(){ 3 char l; 4 while(scanf("%c",&l)!=EOF){ 5 getchar(); 6 if(l == 'r'){ 7 printf("stop!\n"); 8 } 9 else if(l == 'g'){ 10 printf ("go go go\n"); 11 } 12 else if(l == 'y'){ 13 printf("wait a minute\n"); 14 } 15 else 16 printf("something must be wrong...\n"); 17 18 } 19 20 21 22 23 24 25 26 27 28 29 return 0; 30 }
任务二截图
任务三代码
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 5 int main(){ 6 int number,c,i; 7 srand(time(0)); 8 number = rand()%30 + 1; 9 printf("猜猜2023年11月的哪一天是你的lucky day\n开始咯,你有三次机会,猜猜吧(1~30):"); 10 i = 1; 11 while(i <= 3){ 12 scanf("%d",&c); 13 if(c > number){ 14 printf("你猜的日期晚了,你的lucky day已经过了\n"); 15 } 16 else if (c < number){ 17 printf("你猜的日期早了,你的lucky day还没到呢\n"); 18 } 19 else if(c == number){ 20 printf("哇,猜中啦:)"); 21 return 0; 22 } 23 i++; 24 } 25 printf("三次机会已经用光啦!偷偷告诉你,你的幸运日是:11月·%d日",number); 26 27 28 29 30 31 32 return 0; 33 }
任务三截图
任务四
1 #include<stdio.h> 2 int main(){ 3 double s; 4 int n,a,i; 5 s = 0; 6 while(scanf("%d%d",&n,&a)!=EOF){ 7 for(i = 1;i <= n;i++){ 8 s += 1.0*i/a; 9 a = 10*a + a; 10 } 11 printf("n = %d,a = %d,s = %lf\n",n,a,s); 12 13 14 15 16 } 17 18 return 0; 19 }//错误的
正确的
1 #include<stdio.h> 2 int main(){ 3 int n,a,i,k; 4 double s; 5 while(scanf("%d%d",&n,&a)!=EOF){ 6 s = 0; 7 k = 0; 8 for(i = 1;i <= n;i++){ 9 k = 10*k + a; 10 s += 1.0*i/k; 11 } 12 printf("n = %d,a = %d,s = %lf\n\n",n,a,s); 13 14 } 15 16 17 18 19 return 0; 20 }
任务四截图
任务五代码
1 #include<stdio.h> 2 int main(){ 3 int i,j; 4 for(i = 1;i <= 9;i++){ 5 for(j = 1;j <= i;j++){ 6 printf("%d*%d = %d ",i,j,i*j); 7 } 8 printf("\n"); 9 } 10 11 12 13 14 return 0; 15 }
任务五截图
任务六代码
1 #include<stdio.h> 2 int main(){ 3 int n; 4 int i,j,k,l,f; 5 scanf("%d",&n); 6 for(i = 1;i <= n;i++){ 7 for(f=1;f<=i-1;f++){ 8 printf("\t"); 9 } 10 for(j = 1;j <= 2*n-1-2*(i - 1);j++){ 11 printf(" O \t"); 12 } 13 14 printf("\n"); 15 16 for(f=1;f<=i-1;f++){ 17 printf("\t"); 18 } 19 for(k = 1;k <= 2*n-1-2*(i - 1);k++){ 20 printf("<H>\t"); 21 } 22 23 printf("\n"); 24 25 for(f=1;f<=i-1;f++){ 26 printf("\t"); 27 } 28 for(l = 1;l <= 2*n-1-2*(i - 1);l++){ 29 printf("I I\t"); 30 } 31 printf("\n"); 32 33 } 34 35 36 37 38 39 return 0; 40 }
任务六截图
标签:截图,include,int,number,实验,printf,main From: https://www.cnblogs.com/kujievan1/p/17767938.html