首页 > 其他分享 >实验二

实验二

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

任务一

源代码

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

 

 

 

 

图片

问题一: 随机生成397--476范围内的一个数

 问题二:随机生成1--21范围内的一个数

 问题三:随机生成指定数量的学号

 

 

 

 

 

任务二

 源代码

 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     {
 8         if(a==0){
 9             printf("a=0,invalid input\n ");
10             continue;
11         }
12         delta=b*b-4*a*c;
13         p1=-b/2/a;
14         p2=sqrt(fabs(delta))/2/a;
15         if(delta==0)
16           printf("x1=x2=%.2g\n",p1);
17         else if(delta>0)
18           printf("x1=%.2g,x2=%.2g\n",p1+p2,p1-p2);
19         else{
20             printf("x1=%.2g+%.2gi,",p1,p2);
21             printf("x2=%.2g-%.2gi\n",p1,p2);
22         }
23           
24         
25         
26         
27         
28         
29         
30         
31         
32     }
33     return 0;
34     
35     
36 }

图片

 

 

 

 

任务三

 源代码

 

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

 

图片

  

任务四

源代码

 

 1 #include <stdio.h>
 2 int main(){
 3     double sum=0,x,max,min;
 4       max=x;
 5       min=x;
 6       printf("输入今日开销,直到输入-1为止:\n");
 7     scanf("%lf",&x);
 8     while(x>0){
 9         sum=sum+x;
10         if(x>max)
11             max=x;
12         else
13            min=x;
14         scanf("%lf",&x);
15         
16     }
17      printf("今日累计消费总额:%.1lf\n",sum);
18      printf("今日最高一笔开销:%.1lf\n",max);
19      printf("今日最低一笔开销:%.1lf\n",min);
20     
21     return 0;
22     
23 } 

图片

 

任务五

源代码

 

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

 

图片

 

任务六

源代码

 

 1 #include <stdio.h>
 2 #include <time.h>
 3 #define N 3
 4 #define N1 30
 5 int main(){
 6     int luckyday,x;
 7     int cnt;
 8     srand(time(NULL));
 9     luckyday=rand()%N1+1;
10     cnt=0;
11         printf("猜猜2024年11月哪一天会是你的luckyday\n");
12         printf("开始喽,你有三次机会,猜吧(1~30):");
13         
14     while(cnt<N){
15         
16         printf("再猜(1~30):");
17             scanf("%d",&x);
18             
19         if(x<luckyday)
20             {
21             printf("你猜的日期早了,你的luckyday还没到呢\n");
22             }
23         else if(x>luckyday){
24         
25             printf("你猜的日期晚了,你的luckyday在前面哦\n");
26             }
27         else 
28             {
29             printf("哇,猜中了:)\n");
30             break;}
31         cnt++;
32 }
33     
34     if(cnt==N)
35       printf("次数用光啦。偷偷告诉你,11月你的luckyday是%d号\n",luckyday);
36     return 0;
37     
38     
39     
40     
41     
42 }

 

 

图片

 

 

标签:11,%.,int,p1,实验,printf,include
From: https://www.cnblogs.com/qwh061206/p/18455949

相关文章

  • 实验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(......
  • 为何实验室、课题组选择够快云库管理科研资料?
    够快云库提供文件管理服务时,很多高校、科研机构的实验室、课题组选择用够快云库管理组内的文件、资料。和一般团队不同,实验室、课题组的文件以科研文献、实验数据为主,对安全要求高;课题组成员之间文献、实验数据同步、协作需求频繁;还涉及论文的收集、修改……使用中,够快云库......
  • 实验2
    1#include<stdio.h>2#include<math.h>3#include<time.h>4#defineN55#defineN13976#defineN24767#defineN3218intmain()9{10intcnt;11intrandom_major,random_no;12srand(time(NULL));13cnt=0;14while(c......
  • 实验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......