sorry can u delete the above post... max=0; min=999; for(i=0;i,n;i++) {if(a[i]>max) max=a[i]; if(a[i]<min) min=a[i]; } but this requires 2n comparisons.
@kamakshi now you got the question correct.Now you have to optimize number of comparisons to find min and max value. NOTE: Don't ever use min and max value as any fixed value.You can initialize min and max as INT_MIN and INT_MAX.
Given an integer n, write a function that returns count of trailing zeroes in n!. Examples: Input: n = 5 Output: 1 Factorial of 5 is 20 which has one trailing 0. Input: n = 20 Output: 4 Factorial of 20 is 2432902008176640000 which has 4 trailing zeroes. Input: n = 100 Output: 24
I dint get your question...what does less comparisons mean??can you pls explain the question?
ReplyDelete@kamakshi for finding maximum and minimum value in an array you must do some kind of comparison,so we have to optimize that.
ReplyDelete@kamakshi eg arr[]={5,2,3,6,9,8,0};
ReplyDeletemin_value = 0;
max_value = 9;
how do you find this.
sorry can u delete the above post...
ReplyDeletemax=0;
min=999;
for(i=0;i,n;i++)
{if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];
}
but this requires 2n comparisons.
@kamakshi now you got the question correct.Now you have to optimize number of comparisons to find min and max value.
ReplyDeleteNOTE: Don't ever use min and max value as any fixed value.You can initialize min and max as INT_MIN and INT_MAX.