标签:约数 else style bsp rem 公约数 while code int
对分查找
1 int BinarySearch(const int A[], int x, int N) 2 { 3 int low, mid, high; 4 low = 0, high = N - 1; 5 while(low <= high) 6 { 7 mid = (low + high) / 2; 8 if(A[mid] < x) 9 low = mid + 1; 10 else 11 if(A[mid] > x) 12 high = mid - 1; 13 else 14 return mid; 15 } 16 return NotFound; 17 }
欧几里得算法求最大公因数:
1 unsigned Gcd(unsigned int M, unsigned int N) 2 { 3 unsigned int Rem; 4 while(N > 0) 5 { 6 Rem = M % N; 7 M = N; 8 N = Rem; 9 } 10 return M; 11 }
标签:约数 else style bsp rem 公约数 while code int
原文地址:https://www.cnblogs.com/hi3254014978/p/9459172.html