1.实验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 number = rand()%(N2-N1+1)+N1; 18 printf("202383290376%04d\n",number); 19 } 20 return 0; 21 }
问题1:将输出结果的后三位限制在374到465之间
问题2:从202383290376374到202383290376465之间随机挑选5个数
2.实验2
1 #include<stdio.h> 2 3 int main()
4 { 5 char x; 6 7 while(scanf("%c",&x)!=EOF){ 8 getchar(); 9 switch(x){ 10 11 case 'r':printf("stop!\n");break; 12 case 'g':printf("go go go\n");break; 13 case 'y':printf("wait a minute\n");break; 14 default :printf("something must be wrong\n");break; 15 }} 16 return 0;}
3.实验3
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 5 int main() 6 { 7 int x,y,i,z; 8 srand(time(0)); 9 y=rand()%30+1; 10 z=0; 11 printf("猜猜2023年11月哪一天是你的lucky day\n开始喽,你有三次机会,猜吧(1~30):"); 12 13 for (i=0;i<3;++i){ 14 scanf("%d",&x); 15 if(x<y){ 16 z++; 17 printf("你猜的日期早了,你的lucky day还没到\n"); 18 if(z<3) 19 printf("再猜(1~30):");} 20 else if(x>y){ 21 z++; 22 printf("你猜的日期晚了,你的lucky day已经过了\n"); 23 if(z<3) 24 printf("再猜(1~30):");} 25 else{ 26 printf("哇,猜中了 6"); 27 break;} 28 29 if (z==3){ 30 printf("次数用完啦,偷偷告诉你:11月,你的lucky day是%d号\n",y);}} return 0; 31 32 33
4.实验4
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 5 int main(){ 6 double up,down,s; 7 int n,a,i; 8 9 10 while(scanf("%d %d",&n,&a)!=EOF){ 11 up=1.0; 12 s=0; 13 down =a; 14 for(i=1;i<=n;++i){ 15 s=s+up/down; 16 up++; 17 down=down*10+a; 18 } 19 printf("n=%d,a=%d,s=%lf",n,a,s); 20 } 21 22 return 0; 23 24 25 }
5.实验5
1 #include<stdio.h> 2 3 int main(){ 4 int i,j; 5 for(i=1;i<=9;i++){ 6 for(j=1;j<=i;j++) 7 printf("%d*%d=%d ",i,j,j*j); 8 printf("\n"); 9 } 10 11 }
6.实验6
1 #include<stdio.h> 2 3 int main(){ 4 int i,j,n; 5 scanf("%d",&n); 6 for(i=1;i<=n;i++){ 7 for(j=1;j<i;j++) 8 {printf(" ");} 9 10 for (j=1;j<=2*(n-i)+1;j++){ printf(" O "); 11 printf(" ");} 12 printf("\n"); 13 for(j=1;j<i;j++) 14 {printf(" ");} 15 for (j=1;j<=2*(n-i)+1;j++){ 16 printf("<H>"); 17 printf(" ");} 18 printf("\n"); 19 for(j=1;j<i;j++) 20 {printf(" ");} 21 for (j=1;j<=2*(n-i)+1;j++){ 22 printf("I I"); 23 printf(" ");} 24 printf("\n"); 25 26 } 27 return 0; 28 }
标签:11,main,int,C语言,循环,实验,printf,include,分支 From: https://www.cnblogs.com/abcd1235/p/17812774.html