算法设计与分析 2.1时间复杂度分析

文章详细描述了一个C语言函数func,通过嵌套循环实现根据条件计算Temp_1,Temp_2,Temp_3的值,并在满足特定条件后求和。该内容展示了编程中处理逻辑问题的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前五道思考题:

71a3f22a539f4d52b4a83ea96902859c.png

82e513170bdb4958bd49e2b60c86eac5.png

75eeecd323ae4abfa02353afd444cfea.png

354cfe0313a4469a9287b501e4a0a0d8.png

5b66ca8b25b64b29899b9f706ca47afe.png补充:

7d4cf0a248ca41929c4e1b65f339353b.png

 

31b372c8219e4c9caf46b8244ef7c62e.png

Temp=x*y*z
Temp_1=(y*z*i)当Temp_1%x==a
Temp_2=(x*z*i)当Temp_2%y==b
Temp_3=(y*x*i)当Temp_3%z==c
Num=Temp_1+Temp_2+Temp_3当Num<temp;
#include<stdio.h>
void func(int x,int a,int y,int b,int z,int c)
{
	int temp = x * y * z,temp1=0;
	int temp_1=0, temp_2=0, temp_3=0;
	int i=1;
	while(temp_3 % z != c)
	{
		temp_3 = x * y * i;
		i++;
	}
	i = 1;
	while (temp_2 % y != b)
	{
		temp_2 = x * z * i;
		i++;
	}
	i = 1;
	while (temp_1 % x != a)
	{
		temp_1 = z * y * i;
		i++;
	}
	temp1 = temp_1 + temp_2 + temp_3;
	while (temp1 - temp > 0)
	{
		temp1 -= temp;
	}
	printf("%d", temp1);
}
int main()
{
	int x, y, z, a, b, c;
	scanf("%d%d%d%d%d%d", &x, &a, &y, &b, &z, &c);
	func(x, a, y, b, z, c);
}

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值