实验任务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); 18 printf("202383290376%04d\n",number); 19 } 20 21 return 0; 22 }
问题1:随机生成数字加在固定数字后面
问题2:随机生成序列号
实验任务2
1 #include<stdio.h> 2 #include<stdlib.> 3 int main(){ 4 char n; 5 while(scanf("%c",&n)!=EOF){ 6 getchar(); 7 if(n=='y') 8 printf("wait a minute\n"); 9 else if(n=='g') 10 printf("go go go\n"); 11 else if(n=='r') 12 printf("stop\n"); 13 else 14 printf("something goes wrong\n"); 15 } 16 17 return 0; 18 }
实验任务3
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include <time.h> 4 int main(){ 5 printf("猜猜2023年11月哪一天会是你的lucky day\n"); 6 printf("开始喽,你有三次机会,猜吧(1-30)\n"); 7 8 int i,n,date; 9 i = 1; 10 n = 3; 11 srand(time(0)); 12 date=rand()%(30)+1; 13 for(i=1;i<=n;i++){ 14 int a; 15 scanf("%d",&a); 16 if(date>a){ 17 printf("你猜的日期早了,你的lucky day还没到呢\n"); 18 continue;} 19 else if(date<a) 20 {printf("你猜的日期晚了,你的lucky day已经过了\n"); 21 continue;} 22 else{ 23 printf("哇,猜中了:)\n");break;} 24 } 25 if(date!=n) 26 printf("次数用完啦,偷偷告诉你:11月,你的lucky day是%d",date); 27 28 return 0; 29 }
实验任务4
#include<stdio.h> #include<stdlib.h> int main(){ int n,i=1,a; double s=0.0,p; while(scanf("%d %d",&n,&a)!=EOF){ p=a; for(i=1;i<=n;i++){ s+=i*1.0/p; p+=p*10; } printf("n = %d,a = %d,s = %f\n",n,a,s); s=0; } return 0; }
实验任务5
1 #include<stdio.h> 2 int main(){ 3 int i,j,result; 4 for(i=1;i<=9;i++){ 5 for(j=9;j>=i;j--){ 6 printf("%dx%d=%d\t",i,j,result=i*j); 7 }printf("\n"); 8 } 9 return 0; 10 }
实验任务6
1 #include<stdio.h> 2 int main(){ 3 int n; 4 int i,j,k,l,f; 5 scanf("%d",&n); 6 for(i = 1;i <= n;i++){ 7 for(f=1;f<=i-1;f++){ 8 printf("\t"); 9 } 10 for(j = 1;j <= 2*n-1-2*(i - 1);j++){ 11 printf(" O \t"); 12 } 13 14 printf("\n"); 15 16 for(f=1;f<=i-1;f++){ 17 printf("\t"); 18 } 19 for(k = 1;k <= 2*n-1-2*(i - 1);k++){ 20 printf("<H>\t"); 21 } 22 23 printf("\n"); 24 25 for(f=1;f<=i-1;f++){ 26 printf("\t"); 27 } 28 for(l = 1;l <= 2*n-1-2*(i - 1);l++){ 29 printf("I I\t"); 30 } 31 printf("\n"); 32 33 } 34 35 36 37 38 39 return 0; 40 }
标签:include,int,else,实验,printf,main From: https://www.cnblogs.com/dah1428048673/p/17767939.html