首页 > 其他分享 >实验2

实验2

时间:2024-04-10 20:46:26浏览次数:24  
标签:cnt int lucky 实验 printf include day

task1.c

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

#define N 5

int main()
{
	int number;
	int i;

	srand(time(0));

	for (i = 0; i < N; ++i) {
		number = rand() % 65 + 1;
		printf("2023831%04d\n", number);
	}
	return 0;
}

Line 15的作用是 生成一个1~65之间的随机数
这个程序的功能是在202383310001~202310065之间随机生成5个号码

task2.c

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

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

task3.c

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

int main() {
	int lucky_day;
	int guess;
	int cnt;

	srand(time(0));
	lucky_day = rand() % 31 + 1;
	printf("猜猜2024年5月哪一天会是你的lucky_day\n");
	printf("开始喽,你有三次机会,猜吧(1~31):");

	for (cnt = 0; cnt < 3; ++cnt) {
		scanf_s("%d", &guess);

		if (guess == lucky_day) {
			printf("哇,猜中了:-)\n");
			return 0;
		}
		else if (guess < lucky_day) {
			printf("你猜的日期早了,你的lucky_day还没到呢\n");
		}
		else {
			printf("你猜的日期晚了,你的lucky_day在前面哦\n");
		}
		if (cnt < 2)
		{
			printf("\n再猜(1~31):");
		}

	}
	if (cnt == 3) {
		printf("\n\n次数用完了,偷偷告诉你,5月你的lucky_day是%d号\n", lucky_day);
	}
	return 0;
}

task4.c

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

int main() {
	int n, a, j, i,k;
	double s;

	while (scanf_s("%d%d", &n, &a) != EOF) {
		s = 0.0;
		for (i = 1; i <= n; i++) {
			k = 0;
			for (j = 0; j < i; j++) {
				k = k * 10 + a;
		}
			s += 1.0 * i / k;
		}
		printf("n=%d,a=%d,s=%1f\n\n", n, a, s);
	}
	return 0;
}

task5.c

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

int main() {
	int i, j;
	for (i = 1; i <= 9; i++) {
		for (j = 1; j <= i; j++) {
			printf("%d*%d=%d\t", i, j, i * j);
		}
		printf("\n");
	}
	return 0;
}

task6.c

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

int main() {
	int n, i, m, j;
	printf("input n:");
	scanf_s("%d", &n);

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < i; j++)
		{
			printf("\t");
		}
		for (m=2*(n-i)-1;m>0;m--)
		{
			printf(" O \t");
		}
		printf("\n");

			for (j = 0; j < i; j++)
			{
				printf("\t");
		}
		for (m=2*(n-i)-1;m>0;m--) {
			printf("<H>\t");
		}
		printf("\n");

		for (j = 0; j < i; j++)
		{
			printf("\t");
		}
		for (m = 2 * (n - i) - 1; m > 0; m--)
		{
			printf("I I\t");
		}
		printf("\n");
	}
	return 0;
}

标签:cnt,int,lucky,实验,printf,include,day
From: https://www.cnblogs.com/Obsession9/p/18127360

相关文章

  • 20211208葛洺君实验一—3
    任务详情0.查找各种标准的原始文档,研究学习(至少包含CryptoAPI,PKCS#11,GMT0016-2012,GMT0018-2012)1.总结这些API在编程中的使用方式2.列出这些API包含的函数,进行分类,并总结它们的异同3.以龙脉GM3000Key为例,写出调用不同接口的代码(CryptoAPI,PKCS#11,SKF接口),4.把运行截图加......
  • 计算机网络实验九:静态路由与默认路由配置
    目录实验目的实验环境配置实验原理实验步骤及结果实验分析结论实验目的理解静态路由的含义。掌握路由器静态路由的配置方法。理解默认路由的含义。掌握默认路由的配置方法。实验环境配置装有CiscoPacketTracer的Windows计算机。三个路由器(路由器R0、路由器R1、......
  • LCEL的具体实验
    一、基本chainfromlangchain_core.output_parsersimportStrOutputParserfromlangchain_core.promptsimportChatPromptTemplatefromlangchain_community.llms.chatglm3importChatGLM3importosos.environ["LANGCHAIN_TRACING_V2"]="true"os.e......
  • 实验一-密码引擎-3-加密API研究
    一、任务详情密码引擎API的主要标准和规范包括:1微软的CryptoAPI2RAS公司的PKCS#11标准3中国商用密码标准:GMT0016-2012智能密码钥匙密码应用接口规范,GMT0018-2012密码设备应用接口规范等研究以上API接口,总结他们的异同,并以龙脉GM3000Key为例,写出调用不同接口的代码,提交......
  • 20211318 实验一-密码引擎-3-加密API研究
    任务详情:密码引擎API的主要标准和规范包括:微软的CryptoAPIRAS公司的PKCS#11标准中国商用密码标准:GMT0016-2012智能密码钥匙密码应用接口规范,GMT0018-2012密码设备应用接口规范等研究以上API接口,总结他们的异同,并以龙脉GM3000Key为例,写出调用不同接口的代码,提交博客链接......
  • 实验一-密码引擎-3-加密API研究
    实验详情:密码引擎API的主要标准和规范包括:1微软的CryptoAPI2RAS公司的PKCS#11标准3中国商用密码标准:GMT0016-2012智能密码钥匙密码应用接口规范,GMT0018-2012密码设备应用接口规范等研究以上API接口,总结他们的异同,并以龙脉GM3000Key为例,写出调用不同接口的代码,提交博客......
  • 实验一-密码引擎-3-加密API研究
    ##一、任务概览密码引擎API的主要标准和规范包括:1微软的CryptoAPI2RAS公司的PKCS#11标准3中国商用密码标准:GMT0016-2012智能密码钥匙密码应用接口规范,GMT0018-2012密码设备应用接口规范等研究以上API接口,总结他们的异同,并以龙脉GM3000Key为例,写出调用不同接口的代......
  • 实验一-密码引擎-3-加密API研究
    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档目录一、任务详情二、查找各种标准的原始文档,研究学习1.CryptoAPICryptoAPI学习链接:CryptoAPI由五个主要功能区域组成:2.PKCS#113.GMT0016-20124.GMT0018-2012三、总结这些API在编程中的使用方式四、列出这些AP......
  • 实验一-密码引擎3-加密API的研究
    目录一、查找各种标准的原始文档,研究学习Ⅰ.CryptoAPIⅡ.PKCS#11Ⅲ.GMT0016-2012Ⅳ.GMT0018-2012二、总结这些API在编程中的使用方式Ⅰ.CryptoAPIⅡ.PKCS#11Ⅲ.GMT0016-2012Ⅳ.GMT0018-2012三、列出这些API包含的函数,进行分类,并总结它们的异同3.1Cryp......
  • 实验一-密码引擎-3-加密API研究
    0查找各种标准的原始文档,研究学习(至少包含CryptoAPI,PKCS#11,GMT0016-2012,GMT0018-2012)CryptoAPIhttps://learn.microsoft.com/zh-cn/windows/win32/seccrypto/cryptoapi-system-architecture#base-cryptographic-functions微软的CryptoAPI是Win32平台下为应用程序开发者......