task1
问题一:line17作用:限制随机数范围在374~465之间
问题二:程序功能:随时间变化,随机生成在202383290376374~202383290376465之间的数
task2
1 #include<stdio.h> 2 int main(){ 3 char a; 4 while(1){ 5 a=getchar(); 6 getchar(); 7 if(a==EOF){ 8 break; 9 } 10 switch(a){ 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 } 17 return 0; 18 }
task3
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 int main(){ 5 int a,b=1,c=1,d; 6 printf("猜一猜2023年11月哪一天是你的lucky day\n开始喽,你有三次机会,猜吧(1~30):"); 7 srand(time(0)); 8 a=rand()%30+1; 9 while(b<=3){ 10 scanf("%d",&d); 11 if(d>a){ 12 printf("你猜的日期晚了,你的lucky day已经过了\n");} 13 else if(d<a){ 14 printf("你猜的日期早了,你的lucky day还没到呢\n");} 15 else{ 16 printf("哇,猜中了!");c=0;break;} 17 if(b<3) 18 printf("再猜(1~30):"); 19 ++b;} 20 if(c){ 21 printf("\n次数用完了,偷偷告诉你:11月你的lucky day是%d号\n",a);} 22 system("pause"); 23 return 0; 24 }
task4
1 #include<stdio.h> 2 #include<math.h> 3 int haha(int a,int j){ 4 if(j==1){ 5 int b=a; 6 return b; 7 } 8 else { 9 int b=haha(a,j-1)*10+a; 10 return b;} 11 } 12 int main(){ 13 int n,a,i,j,b=0; 14 double s; 15 while(scanf("%d %d",&n,&a)!=EOF){ 16 for(i=1;i<=n;++i){ 17 for(j=1;j<=i;++j){ 18 b=haha(a,j); 19 } 20 s+=1.0*i/b; 21 } 22 printf("n = %d,a = %d,s = %.6lf\n",n,a,s); 23 printf("\n"); 24 b=0; 25 s=0; 26 } 27 return 0; 28 }
task5
#include<stdio.h> int main(){ int i,j,s; for(i=1;i<=9;++i){ for(j=1;j<=i;++j){ s=i*j; printf("%dx%d = %2d ",j,i,s); } printf("\n"); } return 0; }
task6
1 #include<stdio.h> 2 int main(){ 3 printf("input n:"); 4 int i,n,m=0; 5 scanf("%d",&n); 6 while(n!=0){ 7 for(i=0;i<m;++i){ 8 printf(" "); 9 } 10 for(i=0;i<(2*n-1);++i){ 11 printf(" 0 "); 12 } 13 printf("\n"); 14 for(i=0;i<m;++i){ 15 printf(" ");} 16 for(i=0;i<(2*n-1);++i){ 17 printf("<H> "); 18 } 19 printf("\n"); 20 for(i=0;i<m;++i){ 21 printf(" ");} 22 for(i=0;i<(2*n-1);++i){ 23 printf("I I "); 24 } 25 printf("\n"); 26 n-=1; 27 ++m; 28 } 29 return 0; 30 }
标签:main,int,break,while,实验,printf,include From: https://www.cnblogs.com/nuist6/p/17767587.html