task1.c
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 #define N1 374 #define N2 465 int main(){ int number; int i; srand(time(0) ); for (i =0; i< N; i++){ number = rand()%(N2 - N1 + 1) + N1; printf("202383290376%04d\n", number); } return 0; }
实验任务2
1 #include <stdio.h> 2 3 int main(){ 4 char a; 5 while(scanf("%c",&a) != EOF){ 6 getchar(); 7 switch(a){ 8 case 'r':printf("stop!\n");break; 9 case 'y':printf("wait a minute\n");break; 10 case 'g':printf("go go go\n");break; 11 12 default: printf("something must be wrong\n");break; 13 }} 14 return 0; 15 16 17 }
运行结果
实验任务3
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
int number;
srand (time(0));
number = rand()%30 +1;
printf ("猜猜2023年11月哪一天是你的lucky day\n");
printf("开始喽 ,你有三次机会, 猜吧(1~30):");
int a ,i;
i =1;
while(i<=3){
scanf("%d", &a);
if (a<number){
printf("你猜的日期的日期早了 ,你的 lucky day 还没到呢\n再猜:");}
else if(a>number){
printf ("你猜的日期晚了 , 你的lucky day已经过了\n再猜:");
}
else if(a == number )
{printf("哇,猜中了:-)");
return 0;}
i++;
}
printf ("次数用完了 ,偷偷告诉你:11月,你的lucky day 是:%d",number);
return 0;
}
实验任务4
1 #include <stdio.h> 2 #include <stdlib.h> 3 int main () 4 { 5 int n,a; 6 7 while (scanf ("%d%d",&n,&a) != EOF){ 8 int up,down; 9 double s; 10 s = 0; 11 int i; 12 down = 0; 13 14 for (i = 1;i <= n;i++){ 15 up = i; 16 down = 10*down+a; 17 s += 1.0*up/down; 18 19 } 20 printf("n=%d,a=%d,s=%lf\n", n,a,s); 21 } 22 23 24 return 0; 25 26 }
运行结果
实验任务5
1 #include <stdio.h> 2 int main(){ 3 int i,j; 4 for (i = 1;i<= 9; i++){ 5 for(j = 1;j <= i;j++){ 6 printf("%d*%d = %d ",i,j,i*j); 7 } 8 printf("\n"); 9 } 10 11 12 return 0; 13 14 }
运行结果
实验任务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 }
运行结果
标签:11,include,int,number,实验,printf,main From: https://www.cnblogs.com/fz1003yy/p/17767924.html