首页 > 其他分享 >实验2

实验2

时间:2024-04-15 09:58:50浏览次数:19  
标签:main int lucky 实验 printf include day

task1

 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 
19     return 0;
20 }

line15行代码功能是生成一个1~65之间的随机数并存储到number中

整个程序的功能是以系统时间为种子生成5个以“20238331”为前缀,占4位字符的随机数

 task2

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

task3

 1 #include <stdio.h>  
 2 #include <stdlib.h>  
 3 #include <time.h>  
 4   
 5 int main() {  
 6     int lucky_day, guess, i, correct_guess = 0;  
 7     srand(time(NULL));   
 8   
 9     lucky_day = rand() % 31 + 1;  
10   
11     printf("猜猜5月的哪一天是你的lucky day\n");  
12     printf("开始喽,你有三次机会,猜吧(1~31):");  
13   
14     for (i = 1; i <= 3; i++) {  
15         scanf("%d", &guess);  
16   
17         if (guess < lucky_day) {  
18             printf("你猜的日期早了,你的lucky day还没到呢\n");
19             printf("再猜(1~31):");  
20         } else if (guess > lucky_day) {  
21             printf("你猜的日期晚了,你的lucky day在前面哦\n"); 
22             printf("再猜(1~31):"); 
23         } else {  
24             printf("哇,猜中了:-)\n", lucky_day);  
25             correct_guess = 1;  
26             break; 
27         }  
28     }  
29     
30     if (!correct_guess) {  
31         printf("次数用完啦。5月的lucky day是%d号。\n", lucky_day);  
32     }  
33   
34     return 0;  
35 }

task4

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

task5

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

task6

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

 

 

标签:main,int,lucky,实验,printf,include,day
From: https://www.cnblogs.com/3115735030QQ/p/18135202

相关文章

  • 实验2
    1#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()%......
  • 实验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......