实验结论
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;
//随机生成的数大于N1小于N2
14 printf("202383290376%04d\n", number); 15 } 16 return 0; 17 }
task2
1 #include<stdio.h> 2 int main() 3 { 4 char color; 5 while (scanf("%c", &color) != EOF) 6 { 7 getchar(); 8 switch (color) 9 { 10 default: 11 printf("something must be wrong...\n"); 12 break; 13 case 'r': 14 printf("stop!\n"); 15 break; 16 case 'g': 17 printf("go go go\n"); 18 break; 19 case 'y': 20 printf("wait a minute\n"); 21 break; 22 23 } 24 25 } 26 }
task3
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 5 int main() 6 { 7 srand(time(0)); 8 int x; 9 int a = rand() % (30) + 1; 10 printf("猜猜2023年11月哪一天会是你的lucky day\n"); 11 printf("开始喽,你有三次机会,猜吧(1~30):"); 12 for (int i = 1; i <= 3; ++i) 13 { 14 scanf("%d", &x); 15 if (x < a) 16 printf("你猜的日期早了,你的lucky day还没到呢\n再猜(1~30):"); 17 else if (x > a) 18 printf("你猜的日期晚了,你的lucky day已经过啦\n再猜(1~30):"); 19 else 20 printf("哇,猜中了"); 21 } 22 if (x != a) 23 printf("次数用完啦,偷偷告诉你:11月,你的lucky day是%d号", a); 24 }
task4
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 int main(){ 5 int n, a, i, p; 6 while(scanf("%d%d",&n,&a)!=EOF) 7 { 8 double s=0.0; 9 for(i=1,p=0;i<=n;i++) 10 { 11 p+=a*pow(10,i-1); 12 s+=i*1.0/p; 13 } 14 printf("n = %d, a = %d, s = %lf\n",n,a,s); 15 } 16 return 0; 17 }
task5
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int main(){ 5 int i, n, j; 6 for(i=1;i<=9;i++) 7 { 8 for(j=1;j<=i;j++) 9 { 10 n=i*j; 11 printf("%4d*%d = %3d",i ,j ,n); 12 } 13 printf("\n"); 14 } 15 return 0; 16 }
task6
1 #include<stdio.h> 2 #include<stdlib.h> 3 void fundraw(char a,char b,char c,int all,int line) 4 { 5 int j; 6 for(j=0;j<line;j++) 7 { 8 printf("\t"); 9 } 10 int h; 11 for(h = 2*(all-line)-1;h>0;h--) 12 { 13 printf("%c%c%c\t",a,b,c); 14 } 15 printf("\n"); 16 } 17 18 int main() 19 { 20 int i,j,input,h; 21 scanf("%d",&input); 22 for(i=0;i<input;i++) 23 { 24 fundraw(' ','O',' ',input,i); 25 fundraw('<','H','>',input,i); 26 fundraw('I',' ','I',input,i); 27 } 28 return 0; 29 }
标签:11,include,int,break,实验,printf,main From: https://www.cnblogs.com/gui77123456/p/17768477.html