linux C(hello world)最大公约数和最小公倍数

# include <stdio.h>

int  main(void)
{
	int x, y,temp;
	int r; 
	printf("请输入两个正整数:\n");
	scanf("%d %d", &num1, &num2);
	r = num1 % num2;
	temp = num2;
	while(r!=0)
	{
		num1 = num2;
		num2 = r;
		r = num1 % num2;
	}
printf("它们的最大公约数为:%d\n", num2);
	printf("它们的最小公倍数为:%d\n", num1*temp/num2);
	
	return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ChatGPT: 你好,请输入两个正整数m和n,我将为您计算它们的最大公约数和最小公倍数。 用户: 20和30 ChatGPT: 20和30的最大公约数为10,最小公倍数为60。 用户: lua closure factory 完整代码 ChatGPT: 这是一段lua的闭包工厂完整代码,用于创建一个支持闭包的工厂函数: function createFactory() local count = 0 local function getNextCount() count = count + 1 return count end local function createClosure() local closureCount = getNextCount() return function() print("Closure " .. closureCount .. " created.") end end return createClosure end --使用示例: local factory = createFactory() local closure1 = factory() local closure2 = factory() closure1() --输出"Closure 1 created." closure2() --输出"Closure 2 created." 用户: 中文加密 ChatGPT: 中文加密可以使用多种方式,例如替换、移位、乱序等,以下是一种简单的替换方式: function encrypt(str) local keyTable = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} local valueTable = {"z", "y", "x", "w", "v", "u", "t", "s", "r", "q", "p", "o", "n", "m", "l", "k", "j", "i", "h", "g", "f", "e", "d", "c", "b", "a"} local encryptStr = "" for i = 1, #str do local char = string.sub(str, i, i) local index = 0 for j = 1, #keyTable do if (char == keyTable[j]) then index = j break end end if (index == 0) then encryptStr = encryptStr .. char else encryptStr = encryptStr .. valueTable[index] end end return encryptStr end --使用实例: local str = "hello, world!" local encryptStr = encrypt(str) print("加密前:" .. str) print("加密后:" .. encryptStr) --输出"加密后:svool, dliow!"

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值