c语言函数 最大公因数 最小公倍数 折中查找
作者:互联网
//最小因数数
int max(int a, int b)
{
int t,c;
if(a<b)
{
t = a;
a = b;
a = t;
}
c = a%b;
while(c)
{
a = b;
b = c;
c = a%b;
}
return b;
}
//最小公倍数
int min(int a,int b)
{
int ma = max(a,b);
return a*b/ma;
}
//折中查找
void find(int x,int a[],int n)
{
int start = 0,end = n-1,mid;
while(start<=end)
{
mid = (start+end)/2;
if(a[mid] == x)
{
printf("%d",mid+1);
break;
}
if(a[mid] > x) start = mid+1;
if(a[mid] < x) end = mid-1;
}
}
标签:end,折中,公倍数,mid,int,return,start,公因数 来源: https://blog.csdn.net/Hushi1706IT/article/details/110498043