首页 > 其他分享 >实验2

实验2

时间:2024-10-10 13:11:52浏览次数:1  
标签:%. int else p1 实验 printf include

 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<time.h>
 4 #define N 5
 5 #define N1 397
 6 #define N2 476
 7 #define N3 21
 8 int main()
 9 {
10 int cnt ;
11 int random_major,random_no;
12 srand(time(NULL));
13 cnt = 0;
14 while (cnt<N)
15 {random_major =rand ()%2;
16 if (random_major)
17 {random_no=rand()%(N2-N1+1)+N1;
18 printf("20248329%04d\n",random_no);
19 }
20 else {random_no=rand()%N3+1;
21 printf("20248325%04d\n",random_no);
22 }
23 cnt++;}
24 return 0;

问题1,抽取计算机11到12班任意学号
问题2,抽取奇安信班任意学号
问题3,在计算机班中抽取4个任意学号

 1 #include <stdio.h>
 2 #include <math.h>
 3 int main() {
 4     double a, b, c;
 5     double delta, p1, p2;
 6     while (scanf("%lf%lf%lf", &a, &b, &c) != EOF) {
 7         if (a == 0) {
 8             printf("a = 0, invalid input\n");
 9             continue;
10         }
11         delta = b * b - 4 * a * c;
12         p1 = -b / 2 / a;
13         p2 = sqrt(fabs(delta)) / 2 / a;
14         if (delta == 0)
15             printf("x1 = x2 = %.2g\n", p1);
16         else if (delta > 0)
17             printf("x1 = %.2g, x2 = %.2g\n", p1 + p2, p1 - p2);
18         else {
19             printf("x1 = %.2g + %.2gi, ", p1, p2);
20             printf("x2 = %.2g - %.2gi\n", p1, p2);
21         }
22     }
23     return 0;
24 }

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

 1 #include<stdio.h>
 2 int main()
 3 {
 4     double a;
 5     double b = 0;
 6     double max = 0;
 7     double min = 20000;
 8     while (scanf("%lf", &a) != EOF)
 9     {
10         if (a == -1)
11             break;
12         else if (a > max && a < min)
13         {
14             max = a;
15             min = a;
16         }
17         else if (a < min && a < max)
18         {
19             min = a;
20         }
21         else if (a > min && a > max)
22         {
23             max = a;
24         }b = a + b;
25     }
26     printf("今日累计消费:%.1f\n", b);
27     printf("今日最高消费:%.1f\n", max);
28     printf("今日最低消费:%.1f\n", min);
29     return 0;
30 }

 1 #include<stdio.h>
 2 int main()
 3 {
 4     int a, b, c;
 5     while (scanf("%d%d%d", &a, &b, &c) != EOF)
 6         if (a + b <= c || a + c <= b || b + c <= a)
 7         {
 8             printf("不能构成三角形\n");
 9             getchar();
10         }
11         else if (a == b || b == c || c == a)
12         {
13             if (a == b&&b== c)
14                 printf("构成等边三角形\n");
15             else printf("构成等腰三角形\n");
16             getchar();
17         }
18         else if (a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a)
19         {
20             printf("构成直角三角形\n");
21             getchar();
22         }
23         else {
24             printf("构成普通三角形\n");
25             getchar();
26         }return 0;
27 }

 

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

相关文章

  • 实验1 C++
    任务1:task.cpp:1#include<iostream>2#include<string>3#include<vector>4#include<algorithm>56usingnamespacestd;78//声明9//模板函数声明10template<typenameT>11voidoutput(constT&c);1213//......
  • 实验1 C++
    任务1:task1.cpp1//现代C++标准库、算法库体验2//本例用到以下内容:3//1.字符串string,动态数组容器类vector、迭代器4//2.算法库:反转元素次序、旋转元素5//3.函数模板、const引用作为形参67#include<iostream>8#include<string>9......
  • 20222317 2024-2025-1《网络与系统攻防技术》实验一实验报告
    一、实验内容本次实验的对象是一个名为pwn1的linux可执行文件。该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串。该程序同时包含另一个代码片段,getShell,会返回一个可用Shell。正常情况下这个代码是不会被运行的。我们本次实验将学习两种方法运行这......
  • 20222306 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    1.实验内容1.1本周学习内容①Linux基础知识基本的shell命令(例如:ls、cd、cp、touch、cat、su等等)在Linux中熟练使用编译器gcc、调试器gdb,尤其是gdb调试指令(例如:设置断点break/clear、启用/禁用断点enable/disable、运行程序run、继续运行continue、单步代码跟入函数step、查看......
  • java计算机毕业设计实验课程安排与资料管理系统(开题+程序+论文)
    本系统(程序+源码)带文档lw万字以上 文末可获取一份本项目的java源码和数据库参考。系统程序文件列表开题报告内容研究背景在当今高等教育体系中,实验课程作为理论与实践相结合的重要环节,对于培养学生的实践能力和创新思维具有不可替代的作用。然而,传统的人工管理方式在实验......
  • 实验2
    任务1源代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1397#defineN2476#defineN321intmain(){intcnt;intrandom_major,random_no;srand(time(NULL));//以当前系统时间作为随机种子cnt......
  • 20222414 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    实验目的本次实践的对象是一个名为pwn1的linux可执行文件。该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串。该程序同时包含另一个代码片段,getShell,会返回一个可用Shell。正常情况下这个代码是不会被运行的。我们实践的目标就是想办法运行这个代码......
  • 实验2
    实验1#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......
  • #20222309 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    1.实验内容1、直接修改程序机器指令,改变程序执行流程2、通过构造输入参数,造成BOF攻击,改变程序执行流3、注入Shellcode并执行2.实验过程1、直接修改程序机器指令,改变程序执行流程将pwn1改名为pwn20222309-1,并运行打开文件打开文件为乱码按esc键,输入:%!xxd进入十六进制......
  • # 20222323 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    1.实验内容1、熟悉基本的汇编指令,如管道、输入、输出重定向2、掌握了栈与堆的概念3、掌握反汇编与十六进制编程器实验任务1、手工修改可执行文件,改变程序执行流程,直接跳转到getShell函数。2、利用foo函数的Bof漏洞,构造一个攻击输入字符串,覆盖返回地址,触发getShell函数。3、......