首页 > 其他分享 >实验2

实验2

时间:2024-10-13 10:34:45浏览次数:1  
标签:%. int random 3526497 实验 printf include

点击查看代码
#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;


}![](/i/l/?n=24&i=blog/3526497/202410/3526497-20241013094554034-1184849501.png) 1.生成计类11,12班随机学号 2.生成奇安信班级的随机学号 3.随机生成学生的学号
点击查看代码
#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;
}
![](/i/l/?n=24&i=blog/3526497/202410/3526497-20241013095532290-281107407.png)
点击查看代码
#include<stdio.h>
int main()
{
	char r,g,y,ans;
	
	while(scanf(" %c",&ans) != EOF){
	
	if(ans=='r')
	{
		printf("stop!\n");
	}
	else  if(ans=='g')
		printf("go go go\n");

    else if(ans=='y')
	
		printf("wait a minute\n");
	
	else
	
	printf("something must be wrong...\n");

}
    
	return 0;
}

![](/i/l/?n=24&i=blog/3526497/202410/3526497-20241013102506563-245190538.png)
点击查看代码
#include<stdio.h>
#include<stdlib.h>

int main()
{
	int k=0,s=0;
	float all,x,max,min;
	printf("输入今日开销,直到输入-1终止:"); 
	scanf("%f",&x);
	max=x;
	min=x;

	
	while(x>=0){
		s=s+x;
		k++;
		if(x>max) max=x;
		if(x<min) min=x;
		scanf("%f",&x);
	}
	if(k>0)
	{
		all=s*k;
		printf("今日累计消费总额:%.1lf\n,今日最高一笔开销:%.1lf\n,今日最低一笔开销:%.1lf\n",all,max,min);
	}
	system("pause");
	return 0;
}
![](/i/l/?n=24&i=blog/3526497/202410/3526497-20241013102632244-1820950305.png)
点击查看代码
#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*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a)
		printf("直角三角形\n");
		
		else if(a==b&&c==a)
		printf("等边三角形\n");
		
		else if(a==b||a==c||b==c)
		printf("等腰三角形\n");
		
	
		
		else
		printf("普通三角形\n");
	}
	return 0;
	
}
![](/i/l/?n=24&i=blog/3526497/202410/3526497-20241013102717916-651687094.png)
点击查看代码
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

int main()
{
	int luckyDay,guess,maxTries=3;
	srand(time(NULL));
	luckyDay=rand()%30+1;
	printf("开始喽,你有三次机会,猜吧(1~30):");
	for(int i =0;i<maxTries;i++)
	   {
	   scanf("%d",&guess);
	   if(guess<1||guess>30){
	   	printf("输入错误\n");
	   	i--;
	   	continue;
	   }
	   if(guess<luckyDay)
	   printf("你猜的日期早了,你的lucky Day还没到呢\n");
	   else if(guess>luckyDay)
	   printf("你猜的日期晚了,你的lucky Day在前面哦\n");
	   else
	  {
	    printf("哇!猜中了!");
	   return 0; }
}
    printf("很遗憾,你没有猜中。你的luckyDay是%d号。\n",luckyDay);
    return 0;
	
}
![](/i/l/?n=24&i=blog/3526497/202410/3526497-20241013102948906-1867921750.png)

标签:%.,int,random,3526497,实验,printf,include
From: https://www.cnblogs.com/xkzm/p/18461939

相关文章

  • 实验2
    任务1 1#include<stdio.h>2#include<stdlib.h>3#include<math.h>45#defineN56#defineN13977#defineN24768#defineN321910intmain(){11intcnt;12intrandom_major,random_no;1314srand(time......
  • VLAN-IP实验
    需求:1.PC1和PC3所在接口为access接口;属于VLAN2PC2-4-5-6处于同一网段:其中PC2可以访间Pc4-5-6PC4可以访间Pc5不能访间PC6Pc5不能访问Pc63.PC1-Pc3---192.168.0.024与PC2-4-5-6不在一个网段--192.168.1.0244.所有Pc均使用DHcp禁取IP地址,且PC1可以正常访间Pc2-4-5-6第一......
  • 实验2
    实验1代码:1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13977#defineN24768#defineN321910intmain()11{12intcnt;13intrandom_major,random_no;14srand(time(N......
  • 实验2
    #include<stdio.h>#include<malloc.h>#defineSIZE100#defineINCREMENT_SIZE10#defineTRUE1#defineFALSE-1#defineOK1#defineERROR-1typedefintStatus;typedefintElemType;typedefstructLNode{ElemTypedata;structLNode*next;}LNode,*LLi......
  • 实验项目3 自定义路由转换器
    实验目的了解Django处理HTTP请求的流程。掌握路由转换器的用法。掌握如何定义和使用自定义路由转换器。实验内容操作1 创建Django项目chapter02(先进入之前创建的虚拟环境(python3.7、有Django))操作2 在项目chapter02中创建应用app01(应用需要激活应用并分配根路由、创建子......
  • 实验1
    任务1:task1.cpp1//现代C++标准库、算法库体验2//本例用到以下内容:3//1.字符串string,动态数组容器类vector、迭代器4//2.算法库:反转元素次序、旋转元素5//3.函数模板、const引用作为形参67#include<iostream>8#include<string>......
  • 实验2
    task.1#include<stdio.h>#include<stdio.h>#include<time.h>#defineN5#defineN1397#defineN2476#defineN321intmain(){intcnt;intrandom_major,random_no;srand(time(NULL));cnt=0;while(c......
  • 实验一 现代C++编程初体验
    case1://现代C++标准库、算法库体验//本例用到以下内容://1.字符串string,动态数组容器类vector、迭代器//2.算法库:反转元素次序、旋转元素//3.函数模板、const引用作为形参#include<iostream>#include<string>#include<vector>#include<algorithm>usi......
  • 实验1 现代C++编程初体验
    实验1现代C++编程初体验 task1:1//现代C++标准库、算法库体验2//本例用到以下内容:3//1.字符串string,动态数组容器类vector、迭代器4//2.算法库:反转元素次序、旋转元素5//3.函数模板、const引用作为形参6#include<iostream>7#include<strin......
  • 实验1 现代C++基础编程
    task1实验代码:#include<iostream>#include<string>#include<vector>#include<algorithm>usingnamespacestd;//声明//模板函数声明template<typenameT>voidoutput(constT&c);//普通函数声明voidtest1();voidtest2();voidtest3......