实验2
实验2
task 1
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 { 11 int number; 12 int i; 13 14 srand(time(0)); 15 16 for(i=0;i<N;++i){ 17 numnber=rand()%(N2-N1+1)+N1; 18 printf("202383290442%04d\n",number); 19 } 20 ststem("pause"); 21 return 0; 22 }
运行结果

task 2
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() 5 { char x; 6 7 while(scanf("%c",&x) != EOF){ 8 if(x == 'y') 9 printf("wait a minute\n"); 10 else if(x == 'g') 11 printf("go go go\n"); 12 else if(x == 'r') 13 printf("stop\n"); 14 else printf("something must be wrong...\n"); 15 getchar(); 16 } 17 18 19 20 21 system("pause"); 22 return 0; 23 }
运行结果

task3
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 5 int main() 6 { int day,d,i; 7 srand(time(0)); 8 day = rand()%30 + 1; 9 10 printf("猜猜2023年11月哪一天会是你的lucky day\n"); 11 printf("开始喽,你有三次机会,猜吧(1~30):"); 12 scanf("%d",&d); 13 14 for(i = 1; i < 3; i++){ 15 16 if(d == day){ 17 printf("哇,猜中了:-)\n"); 18 system("pause"); 19 return 1; 20 } 21 else if(d < day) 22 printf("你猜的日期早了,你的lucky day还没到呢\n"); 23 else printf("你猜的日期晚了,你的lucky day已经过啦\n"); 24 25 printf("再猜(1~30):"); 26 scanf("%d",&d); 27 } 28 29 printf("次数用完啦。偷偷告诉你:11月,你的lucky day是%d\n",day); 30 31 system("pause"); 32 return 0; 33 }
运行结果

task4
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 5 int main() 6 { int n,a,i; 7 double s; 8 9 while(scanf("%d%d",&n,&a) != EOF){ 10 k = s = 0; 11 for(i = 1; i <= n; i++){ 12 k = 10*k +1; 13 s += 1.0*i/a/k; 14 } 15 printf("n = %d, a = %d, s = %lf",n,a,s); 16 } 17 18 system("pause"); 19 return 0; 20 }
运行结果

task5
1 #include <stdio.h> 2 #include <stdlib.h> 4 5 int main() 6 { int i,j,ans; 7 for(i = 1; i <= 9; i++){ 8 for(j = 1; j <= i; j++){ 9 ans = i*j; 10 printf("%dx%d = %2d ",j,i,ans); 11 } 12 printf("\n"); 13 } 14 system("pause"); 15 return 0; 16 }
运行结果

task 6
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() 5 { int n; 6 int i,j,k; 7 8 scanf("%d",&n); 9 10 for(i = 1; i <= n; i++){ 11 for(j = 1; j < i ; j++) 12 printf("\t"); 13 for(k = 1; k <= 2*(n + 1) - 1 - 2*i; k++) 14 printf(" O \t"); 15 printf("\n"); 16 17 for(j = 1; j < i ; j++) 18 printf("\t"); 19 for(k = 1; k <= 2*(n + 1) - 1 - 2*i; k++) 20 printf("<H>\t"); 21 printf("\n"); 22 23 for(j = 1; j < i ; j++) 24 printf("\t"); 25 for(k = 1; k <= 2*(n + 1) - 1 - 2*i; k++) 26 printf("I I\t"); 27 printf("\n"); 28 } 29 30 system("pause"); 31 return 0; 32 }
运行结果


浙公网安备 33010602011771号