首页 > 其他分享 >实验二

实验二

时间:2024-10-11 16:15:39浏览次数:1  
标签:cnt p1 int else 实验 printf include

实验一:

源代码:

 1 #include<stdio.h>
 2 #include<stdlib.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     int cnt;
10     int random_major,random_no;
11     srand(time(NULL));
12     cnt=0;
13     while(cnt<N){
14         random_major=rand()%2;
15         if(random_major){
16             random_no=rand()%(N2-N1+1)+N1;
17             printf("20248329%04d\n",random_no);
18         }
19         else{
20             random_no=rand()%N3+1;
21             printf("20248395%04d\n",random_no);
22         }
23         cnt++;
24     }
25     return 0;
26 }

运行结果:

问题:line21代码功能为生成一个随机数,范围在397----476

line25再次随机生成一个数,范围在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         if(a==0){printf("a=0,invalid,input\n");
 8         continue;
 9         }
10         delta=b*b-4*a*c;
11         p1=-b/2/a;
12         p2=sqrt(fabs(delta))/2/a;
13         if(delta==0)
14         printf("x1=x2=%.2g\n",p1);
15         else if(delta>0)
16         printf("x1=%.2g,x2=%.2g\n",p1+p2,p1-p2);
17         else{
18             printf("x1=%.2g+%.2gi.",p1,p2);
19             printf("x1=%.2g-%,2gi\n",p1,p2);
20         }
21     }
22     return 0;
23 }

运行结果:

                   

实验三:

源代码:

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

 

运行结果:

实验四:

源代码:

 1 #include<stdio.h>
 2 int main()
 3 {
 4     printf("输入今日的开销,直到输入-1为止:\n");
 5     double a,b=0.0,c=100000000000.0,d=0.0;
 6     int input=1;
 7     while(1){
 8         scanf("%lf",&a);
 9         if(a==-1){
10         break;    
11         }
12         if (input){
13             b=c=a;
14             input=0;
15         }else
16             if(a>b)
17             b=a;
18             if(a<c)
19             c=a;
20     d+=a;
21     }
22     printf("今日最高的一笔花销为:%.1lf\n",b);
23     printf("今日的最高一笔花销为:%.1lf\n",c);
24     printf("今日累计消费:%.lf\n",d);
25     return 0;
26 }

 

运行结果;

 实验五

源代码:

 1 #include <stdio.h>
 2 #include<math.h>
 3 int main(){
 4     double a,b,c;
 5     while(1){
 6         scanf("%lf%lf%lf",&a,&b,&c);
 7     if (a+b>c&&a+c>b&&b+c>a){
 8         if(a==b&&b==c){
 9             printf("这是一个等边三角形\n");
10         }else if(a==b||a==c||b==c){
11             printf("这是一个等腰三角形\n");
12         }else if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a)
13         printf("这是一个直角三角形\n");
14         else
15             printf("这是一个普通三角形\n");
16     } else
17         printf("这不是一个三角形\n");
18     }
19     return 0;
20 }

 

 

运算结果:

 

实验六

源代码:

 1 #include<stdio.h>
 2 int main(){
 3     int a,b,i=1;
 4     srand(time(NULL));
 5     a=rand()%30+1;
 6     printf("猜猜2024年11月哪一天会是你的lucky day\n");
 7     printf("开始喽,你有三次机会,猜吧(1~30):");
 8     while(i<=3){
 9         scanf("%d",&b);
10         if(b==a){
11             printf("哇,猜中了:)");
12             break;
13         }
14         else if(b<a)
15         printf("你猜的日期早了,你的lucky day还没到呢\n");
16         else
17         printf("你猜的日期晚了,你的lucky day在前面呢\n");
18         i++;
19         if(i<=3)
20         printf("再猜(1~30):");
21         else
22         printf("你的次数用光啦,偷偷告诉你,11月你的lucky day是%d号\n",a); 
23     }
24     return 0;
25 }

 

运算结果:

 

标签:cnt,p1,int,else,实验,printf,include
From: https://www.cnblogs.com/1970779615zmh/p/18454727

相关文章

  • 实验二
    task11.line21代码作用:随机生成在N1和N2之间的数字2.line25代码作用:随机生成在1和N3之间的数字3.该程序功能:随机生成五个两个班学生学号task2 task3task4 task5task6 ......
  • 实验2
    实验任务1:task1.c源代码:1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13977#defineN24768#defineN321910intmain()11{12intcnt;13intrandom_major,random_no;14......
  • 实验2
    任务一:代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13977#defineN24768#defineN321910intmain(){11intcnt;12intrandom_major,random_no;1314srand......
  • 数据结构实验第六周
    6-1在一个数组中实现两个堆栈原理就是共享栈,不会的可以看我的数据结构博客StackCreateStack(intMaxSize){StackS=(Stack)malloc(sizeof(structSNode));//这个初始化记得写S->Top1=-1,S->Top2=MaxSize;//栈满的条件S->MaxSize=MaxSize;S->Data=(int......
  • Vchitect 2.0:上海 AI 实验室推出的视频生成利器
    目录引言一、Vchitect2.0模型概述二、Vchitect2.0的技术特点1.超分辨率功能2.帧插入功能3.基于文本和图像的生成能力三、Vchitect2.0的应用场景四、Vchitect2.0测评报告五、生成视频样例六、本地部署推理1.环境准备2.安装依赖3.模型推理结语引言随......
  • 实验2
    任务1源代码1#include<time.h>2#defineN53#defineN13974#defineN24765#defineN3216intmain(){7intcnt;8intrandom_major,random_no;910srand(time(NULL));1112cnt=0;13while(cnt<N){14random_major=rand()%......
  • 实验1 Linux操作系统的安装
    目录1.实验目的和要求:2.主要仪器设备:3.实验内容和原理:(1)实验内容:(2)实验原理:4.操作方法和实验步骤(绘图):5.实验结果与分析(1)将登陆后的效果截图证明系统安装成功(2)回答问题:安装Linux系统一般需要哪些分区?(3)文件和目录类命令的使用(写下你所使用的命令)(4)系统信息类命令......
  • 实验2
    1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45intmain(){6intluckyday,x,y=3;78printf("猜猜2024年11月哪一天会是你的luckyday\n");910srand(time(NULL));11luckyday=rand()......
  • 实验2
    实验2实验任务1:源代码:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1397#defineN2476#defineN321intmain(){intcnt;intrandom_major,random_no;srand(time(NULL));//以当前系统时间作为随机种子cnt......
  • 20222415 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    1.实验内容本周学习了缓冲区溢出的相关知识,介绍了缓冲区和缓冲区溢出,并介绍了几种缓冲区溢出的实现方式。2.实验过程1.直接修改程序机器指令,改变程序执行流程1.1将目标文件pwn20222415通过共享文件夹放到kali里,运行pwn20222415.1.2输入objdump-dpwn1|more对pwn20222415......