M**8 发帖数: 25 | 1 HI, I saw this on internet. Not exactly sure what it wants. Why not use
mulplication instead of ADD, SUB suggested?
int CheckForZero (int a[], int n)
{
int i;
for (i = 0; i < n; i++) {
if (a[i] == 0) {
return (TRUE);
}
}
return (FALSE);
}
This code works - but it does a check for every element in 'a' - i.e.
it does 'n' compares and bails early if it finds even one zero element.
Our array 'a' generally does not have a zero. Optimize this code to
do only one compare. Feel free |
f*****Q 发帖数: 1912 | |
M**8 发帖数: 25 | 3 I doubt AND would work. Can you give more details?
(0xFF00 & 0x00FF) == 0 |
t****t 发帖数: 6806 | 4 oops, my fault. never mind.
【在 M**8 的大作中提到】 : I doubt AND would work. Can you give more details? : (0xFF00 & 0x00FF) == 0
|
l***8 发帖数: 149 | 5 mulplication won't work either because size of machine word is limited (e.g.
32-bit "int"). try multiply 65536 and 65536 and you get back "0". |