首页 > 其他分享 >实验二

实验二

时间:2023-10-16 17:44:06浏览次数:27  
标签:include int scanf 实验 printf go main

任务1

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

 

line17功能: 输入[N1,N2]之间随机数字
功能:学号尾号随机抽取学生



任务2

#include <stdio.h>
int main (){
    char m;
    while(scanf("%c",&m)!=EOF){
        if(m=='r') printf("stop!\n");
        else if(m=='g')    printf("go go go\n");
        else if (m=='y') printf("wait a minute\n");
        else printf("something must be wrong");
    }
}


任务3

#include <stdio.h>
#include <stdlib.h>
int main (){
    int a,i=1,n;
    printf("猜猜哪一天是你的lucky day\n");
    printf("开始咯"); 
    a=rand()%30+1; 
     for(i=1;i<=3;i++){
         scanf("%d",&n);
         if(n==a){
             printf("猜中了");
             break; 
         }
         if(n>a){
             printf("你猜的日期晚了,你的lucky day已经过了\n"); 
             continue;
         }
         if(n<a){
             printf("你猜的日期早了,你的lucky day还没到呢\n");
             continue;
         } 
     }
     if(i>3){
         printf("次数用完了,你的lucky day是%d",a);
     }
}


实验4

#include <stdio.h>
int main (){
    int a,n;
    double t,s;
    while(scanf("%d",&n)!=EOF&&scanf("%d",&a)){
        t=0;
        s=0;
        for(int i=1;i<=n;i++){
            t=a+t;
            s=s+i*1.0/t;
            a=a*10; 
        } 
        printf("%f",s);
        printf("\n"); 
    }
}

任务5

#include <stdio.h>
int main (){
    int n,i=1,s;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        for(int j=1;j<=i;j++){
            s=i*j;
            printf("%dx%d=%d\t",i,j,s);
        }
        printf("\n"); 
    }
}

实验6

#include <stdio.h>
int main (){
    int a=1,b=1,c,n,m,i=1;
    scanf("%d",&n);
   m=n;
    for(i=1;i<=n;i++){
        for(a=1;a<i;a++){
            printf("      ");
        } 
        for(b=1;b<=2*m-1;b++){
             printf(" O ");
            printf("   ");
        }
        printf("\n");
        for(a=1;a<i;a++){
            printf("      ");
        } 
        for(b=1;b<=2*m-1;b++){
            printf("<H>");
            printf("   ");
    }
    printf("\n");
    for(a=1;a<i;a++){
            printf("      ");
        } 
    for(b=1;b<=2*m-1;b++){
            printf("I I");
            printf("   ");
    }
    printf("\n");
    m--;
}
}

 

标签:include,int,scanf,实验,printf,go,main
From: https://www.cnblogs.com/31wqewq/p/17767929.html

相关文章

  • 实验二
    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;......
  • 5381: C++实验:STL之search
    描述  使用STL中的search函数,判断一个序列是否是另一个序列的子序列。部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码。  C++intmain(){vector<int>vec1,vec2;intn,m,a;cin>>n>>m;while(n--){cin>>a;......