首页 > 其他分享 >实验2

实验2

时间:2024-04-14 23:58:04浏览次数:24  
标签:include int 31 lucday 实验 printf main

 1  #include<stdio.h>
 2  #include<stdlib.h>
 3  #include<time.h>
 4  
 5  #define N 5
 6  
 7  int main()
 8  {
 9      int number;
10      int i;
11 
12      srand(time(0));
13 
14      for(i=0;i<N;++i){
15          number = rand()%65 +1;
16          printf("20238331%04d\n",number);
17      }
18      system("pause");
19      return 0;
20  }

 

line15功能为:生成1到65的随机数
程序的功能是:生成202383310001到202383310065之间的五个随机学号

 

task2

 1 #include<stdio.h>
 2  #include<stdlib.h>
 3   
 4  int main()
 5  {
 6      char color;
 7  
 8      while(scanf_s("%c",&color)!=EOF)
 9      {
10          switch(color)
11          {
12          case'r':printf("stop!\n");
13                          break;
14          case'g':printf("go go go\n");
15                          break;
16          case'y':printf("wait a minute\n");
17                          break;
18          default:printf("something must be wrong...\n");
19                          break;
20          }
21          getchar();
22      }
23  
24      system("pause");
25      return 0;
26  }

 

 

task3

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <time.h>
 4 
 5 int main()
 6 {
 7     int lucday, a, b = 0;
 8 
 9     srand(time(0));
10     lucday = rand() % 31 + 1;
11     printf("猜猜2024年5月哪一天会是你的lucky day\n\n");
12     printf("开始喽,你有三次机会,猜吧(1~31):");
13 
14     while (b < 3)
15     {
16         scanf_s("%d", &a);
17         printf("\n");
18 
19         if (a == lucday)
20         {
21             printf("哇,猜中了:-)\n");
22             return 0;
23         }
24         else if (a < lucday)
25         {
26             printf("你猜的日期早了,你的lucky day还没到呢\n");
27         }
28         else
29         {
30             printf("你猜的日期晚了,你的lucky day在前面哦\n");
31         }
32 
33         if (b < 2)
34         {
35             printf("\n再猜(1~31):");
36         }
37 
38         b++;
39     }
40 
41     if (b == 3)
42     {
43         printf("\n\n次数用完了,偷偷告诉你,5月你的lucky day是%d号\n", lucday);
44     }
45 
46     return 0;
47 }

 

task4

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 int main() {
 5     int n, a, j, i, k;
 6     double s=0.0;
 7 
 8     while (scanf_s("%d%d", &n, &a) != EOF) {
 9         
10         for (i = 1; i <= n; i++) {
11             k = 0;
12             for (j = 0; j < i; j++) {
13                 k = k * 10 + a;
14             }
15             s += (double)i / k;
16         }
17         printf("n=%d,a=%d,s=%1f\n\n", n, a, s);
18     }
19     return 0;
20 }

 

task5

int main()
{
    int a = 0;
    for (a = 1;a <= 9;a++)
    {
        int b = 0;
        for (b = 1;b <= i;b++)
            printf("%d*%d=%2d\t ", a, b, a * b);
        printf("\n");

    }
    return 0;
}

 

 

task6

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

 

标签:include,int,31,lucday,实验,printf,main
From: https://www.cnblogs.com/aolan0705/p/18134958

相关文章

  • 实验2
    任务11#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN567intmain()8{9intnumber;10inti;1112srand(time(0));1314for(i=0;i<N;++i){15number=rand()%65......
  • 实验二
    1.实验任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n",......
  • 实验2
    task1.c#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%......
  • 实验2
    实验一#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n",number......
  • 实验2
    任务一:`#include<stdio.h>include<stdlib.h>include<time.h>defineN5intmian(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n",number);}return0;}`问题1:生成1到65的随机数问题2......
  • 原型设计实验
    原型设计工具比较分析:墨刀:适用领域:墨刀适用于快速原型设计和交互设计,特别适合移动应用和Web应用的设计。优点:界面简洁清晰,易于上手,适合初学者和团队合作。支持多种交互模式,如链接、滑动、弹出框等,可以较好地模拟用户操作流程。支持团队协作,可以多人同时编辑同一项目,方便团队......
  • 实验2_C语言分支与循环基础应用编程
    实验任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){ intnumber; inti; srand(time(0)); for(i=0;i<N;++i){ number=rand()%65+1; printf("20238331%04d\n",number); } return0;}......
  • 实验2
    实验1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;//控制随机数的范围从1~66printf("2023......
  • 实验2
    TASK1点击查看代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){ intnumber; inti; srand(time(0)); for(i=0;i<N;++i){ number=rand()%65+1; printf("2023833%04d\n",number); } ret......
  • 实验二
    task1点击查看代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("202......