int l=(int)(log(n)/log2)+1; int i=0,j=l; while(i < j){ if(( n & (1 << i)) == ( n & (1 << j))){ i++; j--; } else{ break; } } if(i >= j)cout << "no. is a palindrome"; else cout << "no. is not a palindrome";
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
int l=(int)(log(n)/log2)+1;
ReplyDeleteint i=0,j=l;
while(i < j){
if(( n & (1 << i)) == ( n & (1 << j))){
i++;
j--;
}
else{
break;
}
}
if(i >= j)cout << "no. is a palindrome";
else cout << "no. is not a palindrome";
@jainendra according to your understanding do you consider 1010 as palindrome or not.If yes then your program doesn't check for even length number.
ReplyDelete