首页 > 其他分享 >实验2

实验2

时间:2024-10-10 15:34:09浏览次数:1  
标签:%. int else p1 实验 printf include

task.1

代码

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define N 5
#define N1 397
#define N2 476
#define N3 21
int main(){
    int cnt;
    int random_major,random_no;
    srand(time(NULL));
    cnt=0;
    while(cnt<N){
        random_major=rand()%2;
        if(random_major){
            random_no=rand()%(N2-N1+1)+N1;
            printf("20248329%04d\n",random_no);
        }
        else{
            random_no=rand()%N3+1;
            printf("20248395%04d\n",random_no);
        }
        cnt++;
    }
    return 0;

}

图片

问题1:将random_no取397~476

问题2:将random_no取0~21

问题3:在学号83290397~83290476与83290000~83290021抽取5位

task.2

代码

#include<stdio.h>
#include<math.h>
int main(){
    double a,b,c;
    double delta,p1,p2;
    while(scanf("%lf%lf%lf",&a,&b,&c)!=EOF){
        if(a==0){
            printf("a=0,invalid input\n");
            continue;
        }
        delta=b*b-4*a*c;
        p1=-b/a/2;
        p2=sqrt(fabs(delta))/a/2;
        if(delta==0){
            printf("x1=x2=%.2g\n",p1);
        }
        else if(delta>0){
            printf("x1=%.2g,x2=%.2g\n",p1+p2,p1-p2);
        }
        else{
            printf("x1=%.2g+%.2gi",p1,p2);
            printf("x1=%.2g-%.2gi",p1,p2);
        }
    }
    return 0;
}

图片

 

task.3

代码

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

图片

task.4

代码

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main()
{
    printf("输入今日开销,直到输入-1终止:\n");
    double x,max,min,s;
    scanf("%lf", &x);
    s = 0;
    max = x;
    min = x;
    while (x!=-1)
    {
        s = s + x;
        if (max < x)
            max = x;
        if (min > x)
            min = x;
        scanf("%lf", &x);
    }
    printf("今日累计消费总额:%.1f\n今日最高一笔开销:%.1f\n今日最低一笔开销:%.1f\n", s, max, min);
    return 0;
}

 

 图片

task.5

代码

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int a, b, c;
    while (scanf("%d%d%d", &a, &b, &c) != EOF)
    {
        if (a + b > c && a - b < c)
        {
            if (a == b && b == c)
                printf("等边三角形\n");
            else if (a == b || b == c || a == c)
                printf("等腰三角形\n");
            else if (a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a)
                printf("直角三角形\n");
            else
                printf("普通三角形\n");
        }
        else
            printf("不能构成三角形\n");
    }
    return 0;
}

图片

 

task.6

代码

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
    int x, s, n=0;
    printf("猜猜2024年11月那一天会是你的lucky day\n开始喽,你有三次机会,猜吧(1~30):");
    srand(time(NULL));
    x = rand() % 30 + 1;
    while (n <2)
    {
        scanf("%d", &s);
        n++;
        if (s > x)
            printf("\n你猜的日期晚了,你的lucky day在前面哦\n再猜(1~30):");
        else if (s < x)
            printf("\n你猜的日期早了,你的lucky day还没到呢\n再猜(1~30):");
        else
        {
            printf("哇,猜中了:)");
            continue;
        }
    }
    scanf("%d", &s);
    if (s > x)
        printf("\n你猜的日期晚了,你的lucky day在前面哦\n");
    else if (s < x)
        printf("\n你猜的日期早了,你的lucky day还没到呢\n");
    else
        printf("哇,猜中了:)");
        printf("\n次数用光啦。偷偷告诉你,11月你的lucky day是%d号", x);
        return 0;
    }
        

图片

标签:%.,int,else,p1,实验,printf,include
From: https://www.cnblogs.com/frogwithtrousers/p/18455095

相关文章

  • 20222326 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    一、实验内容Linux基本操作的学习能熟练的熟悉文件修改、打开,查看文件夹内容能正常使用gdb、vi可以理解汇编语言、机器指令、EIP的内容等理解可执行文件和机器指令例如call指令反汇编指令objdump文件十六进制转换指令%!xxd与%!xxd-r逆向工程学习如何分析和......
  • 实验二 C语言分支与循环基础应用编程-1
    task1.c #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1397#defineN2476#defineN321intmain(){intcnt;intrandom_major,random_no;srand(time(NULL));//以当前系统时间作为随机种子cnt=0;while(cnt<N){rando......
  • 实验2
    任务1源代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13977#defineN24768#defineN321910intmain(){11intcnt;12intrandom_major,random_no;1314srand(t......
  • 20222419 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    1.实验内容1.1本周学习内容(1)了解了缓冲区溢出发展历史:红色代码、冲击波病毒、震荡波病毒、心脏出血、乌克兰断网、勒索病毒。(2)了解了缓冲区溢出漏洞的本质和危害:缓冲区溢出漏洞是由于程序没有进行严格的内存越界检查,导致数据溢出并覆盖相邻内存空间,从而可能被攻击者利用执行恶......
  • 实验1 现代c++基础编程
    任务1:源代码task1.cpp//现代C++标准库、算法库体验//本例用到以下内容://1.字符串string,动态数组容器类vector、迭代器//2.算法库:反转元素次序、旋转元素//3.函数模板、const引用作为形参#include<iostream>#include<string>#include<vector>#include......
  • 实验1 c++
    任务1:task1.cpp1#include<iostream>2#include<string>3#include<vector>4#include<algorithm>56usingnamespacestd;78//声明9//模板函数声明10template<typenameT>11voidoutput(constT&c);1213//......
  • 实验二
    任务一源代码1#include<stdio.h>2#include<time.h>34#defineN55#defineN13976#defineN24767#defineN3218intmain(){910intrandom_major,random_no;11intcnt;12srand(time(NULL));1314cnt=......
  • 实验2
    实验任务1:1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13977#defineN24768#defineN321910intmain(){11intcnt;12intrandom_major,random_no;1314srand(......
  • 实验2
    任务11#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13977#defineN24768#defineN321910intmain(){11intcnt;12intrandom_major,random_no;1314srand(time(......
  • 为何实验室、课题组选择够快云库管理科研资料?
    够快云库提供文件管理服务时,很多高校、科研机构的实验室、课题组选择用够快云库管理组内的文件、资料。和一般团队不同,实验室、课题组的文件以科研文献、实验数据为主,对安全要求高;课题组成员之间文献、实验数据同步、协作需求频繁;还涉及论文的收集、修改……使用中,够快云库......