实验任务1
task1.c
源代码:
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 21 return 0; 22 }
运行截图:
实验任务2
task2.c
源代码:
1 #include <stdio.h> 2 3 int main() 4 { 5 char c; 6 7 while(scanf("%c",&c)!=EOF){ 8 if(c=='r'){ 9 printf("stop!"); 10 } 11 else if(c=='g'){ 12 printf("go go go"); 13 } 14 else if(c=='y'){ 15 printf("wait a minute"); 16 } 17 } 18 19 return 0; 20 }
运行截图:
实验任务3
task3.c
源代码:
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 5 int main() 6 { 7 srand((unsigned int)time(0)); 8 int rand_number=rand()%30+1; 9 int rate=1; 10 const int n=3; 11 12 printf("猜猜2023年11月哪一天会是你的lucky day\n"); 13 printf("开始喽,你有三次机会,猜吧(1~30):"); 14 int i=1; 15 16 for( i=1;i<=n;i++){ 17 scanf("%d",&rate); 18 if(rate<rand_number){ 19 printf("你猜的日期早了,你的lucky day还没到呢\n"); 20 }else if(rate>rand_number){ 21 printf("你猜的日期晚了,你的lucky day已经过啦\n"); 22 }else if(rate==rand_number){ 23 printf("哇,猜中了\n"); 24 break; 25 } 26 27 if(i!=3) 28 printf("再猜:"); 29 } 30 31 if(i==4){ 32 printf("\n"); 33 printf("次数用完了,偷偷告诉你,11月,你的lucky day是%d号",rand_number); 34 } 35 36 37 38 return 0; 39 40 }
运行截图:
实验任务4
源代码:
1 #include <stdio.h> 2 #include <math.h> 3 4 int haha(int a,int j){ 5 if(j==1){ 6 int b=a; 7 return b; 8 } 9 else{ 10 int b=haha(a,j-1)*10+a; 11 return b; 12 } 13 } 14 int main() 15 { 16 int n,a,i,j,b=0; 17 double s; 18 while(scanf("%d %d",&n,&a)!=EOF){ 19 for(i=1;i<=n;i++){ 20 for(j=1;j<=i;j++){ 21 b=haha(a,j); 22 } 23 s+=1.0*i/b; 24 } 25 26 printf("n=%d,a=%d,s=%.6lf\n",n,a,s); 27 printf("\n"); 28 b=0; 29 s=0; 30 } 31 return 0; 32 }
运行截图:
实验任务5
源代码:
1 #include <stdio.h> 2 3 int main() 4 { 5 int i,j; 6 for(i=1;i<=9;i++){ 7 for(j=1;j<=i;j++){ 8 printf("%d*%d=%d\t",j,i,i*j); 9 } 10 printf("\n"); 11 } 12 13 return 0; 14 }
运行截图:
实验任务6
源代码:
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() 5 { 6 int n; 7 int i,l,f,k,j; 8 9 scanf("%d",&n); 10 11 for(i=1;i<=n;i++){ 12 int m; 13 for(m=1;m<=i-1;m++){ 14 printf("\t"); 15 } 16 for(j=1;j<=2*n-1-2*(i-1);j++){ 17 printf(" O\t"); 18 } 19 printf("\n"); 20 21 for(k=1;k<=i-1;k++){ 22 printf("\t"); 23 } 24 for(f=1;f<=2*n-1-2*(i-1);f++){ 25 printf("<H>\t"); 26 } 27 printf("\n"); 28 29 for(k=1;k<=i-1;k++){ 30 printf("\t"); 31 } 32 for(l=1;l<=2*n-1-2*(i-1);l++){ 33 printf("I I\t"); 34 } 35 printf("\n"); 36 37 } 38 39 system("pause"); 40 return 0; 41 }
运行截图:
标签:11,main,源代码,int,编程,C语言,printf,include,分支 From: https://www.cnblogs.com/st5114-/p/17767936.html