首页 > 其他分享 >实验2

实验2

时间:2024-10-09 19:10:36浏览次数:1  
标签:int pay else 实验 printf include luck

task1

点击查看代码
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define N 5
#define N1 397
#define N2 476
#define N3 21

int main()
{
	
	int cnt;
	int random_no,random_major;
	
	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;
}

21 抽397到476的同学
25 0 21
随机抽取在座的5名同学

task2

点击查看代码
#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/2/a;
        p2 = sqrt(fabs(delta))/2/a;

        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("x2 = %.2g - %.2gi\n", p1, p2);
        }
    }

    return 0;
}

task3

点击查看代码
#include<stdio.h>

int main()
{
	char a;
	
	while( (scanf("%c",&a)) != EOF)
	{
		getchar();
		
		if     ( a == 'g' || a == 'G')
			printf("go go go\n");
		else if( a == 'y' || a == 'Y')
			printf("wait a minute\n");
		else if( a == 'r' || a == 'R')
			printf("stop!\n");
		else
			printf("something must be wrong...\n");
			
	}
	return 0;
}

================================================================================================
task4

点击查看代码
#include<stdio.h>

int main()
{

	double pay , sum = 0.0 , max=0.0 , min=20000.0;
	
	printf("输入今天的开销直至-1终止\n");
	while((scanf("%lf",&pay)) != EOF )
	{
		
		if(pay == -1)
			break;
			
		sum = sum + pay;
		
		if(pay > max)
			max = pay;
			
		if(pay < min)
			min = pay;
			
		
	}
	
	printf("最高一笔开销%lf\n最低一笔开销%lf\n一天总开销%lf\n",max,min,sum);
}

点击查看代码
#include<stdio.h>

int main()
{
	int a,b,c;
	
	while((scanf("%d %d %d",&a,&b,&c)) != EOF)
	{
		if	     (a+b<c || a+c<b || b+c<a)
			printf("不能构成三角形\n");
			
		else if  (a == b || a == c || b == c)
		    if(a == b && a ==c && b == c)
		    	printf("等边三角形\n");
			else
				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");
			
	}
	return 0;
}
![](/i/l/?n=24&i=blog/3527145/202410/3527145-20241009185204397-1519699641.png)

=============================================================================================================

task6

点击查看代码
#include<stdio.h>

#define N 1
#define N1 30

int main()
{
	int luck,i,gus;
	i = 0;
	
	srand(time(NULL));
	luck = rand() % ( N1 - N + 1) + 1;
	
	printf("开始喽,你有三次机会,猜吧(1~30):");
	while ( i < 3 )
		{
			scanf("%d",&gus);
			
			if     (gus < luck)
				printf("你猜的日期早了,你的luck日在后面哦\n");
			else if(gus = luck)
			{
				printf("哇猜中了:)");
				break;
			}
			else
				printf("你猜的日期晚了,你的luck日在前面哦\n");
				
			
			if (i < 2)
				printf("在猜(1~30):");
			else if(i == 2)
				printf("次数用完了。偷偷告诉你,11月你的luck day是%d号哦",luck);
			
			i++;
		}

	
	return 0;
		 
}


标签:int,pay,else,实验,printf,include,luck
From: https://www.cnblogs.com/yzyzyz/p/18454588

相关文章

  • 实验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......
  • 20222327 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    一.实验内容1.了解Linux系统下的基本操作命令,能够处理一些命令出现的error。2.掌握了栈与堆的概念以及在进程内存管理中的应用。3.了解基本的汇编语言指令及其功能。4.能够深刻理解BoF的原理以及如何运用payload完成BoF的攻击二.实验过程任务一直接修改程序机器指令,改变程......
  • 实验二
    任务一1#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#defineN55#defineN13976#defineN24767#defineN3218intmain(){9intcnt;10intrandom_major,random_no;11srand(time(NULL));//以当前系统时间作为随机种子......
  • 实验二
    任务一验证性实验源码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1397#defineN2476#defineN321intmain(){intcnt;intrandom_major,random_no;srand(time(NULL));//以当前系统时间作为随机种子......
  • 实验一
    实验任务1://现代C++标准库、算法库体验//本例用到以下内容://1.字符串string,动态数组容器类vector、迭代器//2.算法库:反转元素次序、旋转元素//3.函数模板、const引用作为形参#include<iostream>#include<string>#include<vector>#include<algorithm>u......
  • 实验一 C++
    实验任务1:task1.cpp:1#include<iostream>2#include<string>3#include<vector>4#include<algorithm>56usingnamespacestd;78//声明9//模板函数声明10template<typenameT>11voidoutput(constT&c);1213......
  • OOP实验一
    任务1:源码:1#include<iostream>2#include<string>3#include<vector>4#include<algorithm>5usingnamespacestd;6//声明7//模板函数声明8template<typenameT>9voidoutput(constT&c);10//普通函数声明11voidtes......
  • 实验1 现代C++编程初体验
    任务一#include<iostream>#include<string>#include<vector>#include<algorithm>usingnamespacestd;template<typenameT>voidoutput(constT&c);voidtest1();voidtest2();voidtest3();intmain(){cout<<&qu......
  • 实验1
    #include<iostream>#include<string>#include<vector>#include<algorithm>usingnamespacestd;template<typenameT>voidoutput(constT&c);voidtest1();voidtest2();voidtest3();intmain(){cout<<&qu......
  • 《DNK210使用指南 -CanMV版 V1.0》第二十八章 音频播放实验
    第二十八章音频播放实验1)实验平台:正点原子DNK210开发板2)章节摘自【正点原子】DNK210使用指南-CanMV版V1.03)购买链接:https://detail.tmall.com/item.htm?&id=7828013987504)全套实验源码+手册+视频下载地址:http://www.openedv.com/docs/boards/k210/ATK-DNK210.html5)正点原......