C.exam.2

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <time.h>
 4 
 5 #define N 5
 6 int main()
 7 {
 8     int number;
 9     int i;
10     
11     srand( time(0));
12     
13     for(i=0;i<N;++i){
14         number=rand()%65 + 1;//随机生成1—65中的一个数 
15         printf("20238331%04d\n",number);
16         
17     }
18     return 0;
19  }
20   // 随机生成 202383310001-202383310065 中的 5 个数 

 1 #include <stdio.h>
 2 
 3 int main() {
 4     char light; // 用于存储用户输入的字符
 5 
 6     // 使用while循环支持多组输入
 7     while (scanf("%c", &light) != EOF) { 
 8       getchar();
 9         switch (light) {
10             case 'r':
11                 printf("stop!\n");
12                 break;
13             case 'g':
14                 printf("go go go\n");
15                 break;
16             case 'y':
17                 printf("wait a minute\n");
18                 break;
19             default:
20                 printf("something must be wrong.\n");
21         }
22     }
23 
24     return 0;
25 }

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <time.h>
 4 
 5 int main() {
 6     int lucky_day, guess, attempts = 3;
 7 
 8     // 初始化随机数生成器
 9     srand(time(NULL));
10 
11     // 生成1到31之间的随机整数作为幸运日
12     lucky_day = rand() % 31 + 1;
13 
14     printf("欢迎来到5月幸运日游戏!你有三次机会猜中幸运日。\n");
15 
16     do {
17         // 提示用户输入猜测的日期
18         printf("请输入你猜测的日期(1-31):");
19         scanf("%d", &guess);
20 
21         // 检查用户的猜测
22         if (guess == lucky_day) {
23             printf("恭喜你,猜中了!\n");
24             break;
25         } else if (guess < lucky_day) {
26             printf("猜的日期早了。\n");
27         } else {
28             printf("猜的日期晚了。\n");
29         }
30 
31         // 减少尝试次数
32         attempts--;
33 
34         // 如果还有尝试机会,告诉用户剩余次数
35         if (attempts > 0) {
36             printf("你还有%d次机会。\n", attempts);
37         }
38     } while (attempts > 0);
39 
40     // 如果用户没有猜中,显示幸运日
41     if (attempts == 0) {
42         printf("很遗憾,你没有猜中。5月的幸运日是%d号。\n", lucky_day);
43     }
44 
45     return 0;
46 }

 1 #include<stdio.h>
 2 int main()
 3 {
 4     int n,a,i,up,down;
 5     double s,ans;
 6     ans=0;
 7     printf("请输入正整数n和a:");
 8     while(scanf("%d %d",&n,&a)!=EOF) {
 9     
10     for(i=1,s=0,down=0;i<=n;i++)
11     {
12         up=i;
13         down=down*10+a;
14         ans=up*1.0/down;
15         s=s+ans;
16     }
17     printf("n=%d,a=%d,s=%f",n,a,s);
18         printf("\n请输入正整数n和a:");}
19     return 0;
20  } 

 1 #include <stdio.h>
 2 
 3 int main() {
 4     for (int i = 1; i <= 9; i++) {
 5         for (int j = 1; j <= i; j++) {
 6             printf("%d*%d=%-2d ", j, i, i * j);
 7         }
 8         printf("\n");
 9     }
10     return 0;
11 }

 1 #include<stdio.h>
 2 
 3 int main(){
 4     int n,i,k,j;
 5     printf("input n:");
 6     scanf("%d",&n);
 7     for(i=0;i<n;i++){
 8         for(k=0;k<i;k++){
 9             printf("\t");
10         }
11         for(j=2*(n-i)-1;j>0;j--){
12             printf(" o \t");
13         }
14         printf("\n");
15         for(k=0;k<i;k++){
16             printf("\t");
17         }
18         for(j=2*(n-i)-1;j>0;j--){
19             printf("<H>\t");
20         }
21         printf("\n");
22         for(k=0;k<i;k++){
23             printf("\t");
24         }
25         for(j=2*(n-i)-1;j>0;j--){
26             printf("I I\t");
27         }
28         printf("\n");
29     }
30     return 0;
31 } 

 

posted @ 2024-04-15 00:17  dxian  阅读(3)  评论(0编辑  收藏  举报