Consider the following code:
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.We need to optimize this code to do only one compare. use some mathematical
operations such as ADD, SUB etc.
Please reply to this question
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.We need to optimize this code to do only one compare. use some mathematical
operations such as ADD, SUB etc.
Please reply to this question
Comment