首页 > 其他分享 >实验二

实验二

时间:2023-10-16 17:44:39浏览次数:36  
标签:int 30 源码 实验 printf date include

一.实验任务一

源码

#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);
    }

    system("pause");
    return 0;
}

运行结果

作用

产生[N1,N2]间的随机整数

二.实验任务二

源码

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

三.实验任务三

源码

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

效果

 

 四.实验任务四

源码

 

标签:int,30,源码,实验,printf,date,include
From: https://www.cnblogs.com/sanski/p/17767919.html

相关文章

  • 实验二
    任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;i++){number=rand()%(N2-N1+1)+N1;pri......
  • 实验二
    task1.c源代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain()10{11intnumber;12inti;1314srand(time(0));1516for(i=0;i......
  • 实验2
    task1line17功能是在(N2-N1+1)+N1之间随机选取一个数字代码功能是随机生成学号 task21#include<stdio.h>2intmain()3{4charcolour;56while(scanf("%c",&colour)!=EOF){7if(colour>='a'&&colour<=......
  • 实验室信息化管理系统LIMS,实现实验室数据和信息的收集、分析、陈述和处理
    实验室信息化管理系统LIMS,由计算机硬件和应用软件组成,能够实现实验室数据和信息的收集、分析、陈述和处理。实验室信息化管理系统LIMS是以查验检测作业为中心,包含一个以样品分析为主线的从样品登录、登记处理、查验检测、数据计算分析到成果输出等流程的处理,实验室信息处理系统LIMS......
  • 实验四 信号量
    使用二值信号量解决多线程售票系统数据错误问题实现代码#include<stdio.h>#include<pthread.h>#include<unistd.h>#include<semaphore.h>intticketAmout=2;//票的数量:全局变量sem_tmutex;//定义信号量mutexvoid*ticketAgent(void*arg){sem_wait(&mut......
  • 实验1 类和对象编程_基础编程1
    实验任务1task1.cpp//标准库string,vector,array基础用法#include<iostream>#include<string>#include<vector>#include<array>//函数模板//对满足特定条件的序列类型T对象,使用范围for输出template<typenameT>voidoutput1(constT&obj){for(aut......
  • 实验一
    任务一1#include<iostream>2#include<string>3#include<vector>4#include<array>5template<typenameT>6voidoutput1(constT&obj)7{8for(autoi:obj)9std::cout<<i<<",";10......
  • 实验三 互斥锁
    不加锁的多线程售票系统存在的问题售票系统实现代码#include<stdio.h>#include<pthread.h>#include<unistd.h>intticketAmout=2;//票的数量:全局变量void*ticketAgent(void*arg){intt=ticketAmout;if(t>0){printf("Oneticketsold\n");t--;}el......
  • 实验四报告: 熟悉Python字典、集合、字符串的使用
    实验目标本实验的主要目标是熟悉Python中字典、集合、字符串的创建和操作,包括字典的创建、访问、修改和合并,集合的创建、访问以及各种集合运算,以及字符串的创建、格式化和常用操作。实验要求通过编写Python代码,验证以下要求:熟悉Python字典的创建、访问、修改、合并。熟悉Pyt......
  • 可实现加、减、乘、除、开平方的计算器软件的实验设计
    1、思路代码:#include<stdio.h>#include<math.h>//牛顿迭代法计算平方根doublesqrt_newton(doublex){doubleguess=x/2.0;//初始猜测值为x的一半doubledelta=0.000001;//误差范围while(fabs(guess*guess-x)>delta){guess=(guess+x/guess)/2.0;......