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
Posts
Void pointers: Difference between c and c++
- Get link
- X
- Other Apps
By
Admin
-
I'm trying to understand the differences between C and C++ with regards to void pointers. the following compiles in C but not C++ : int * p = malloc ( sizeof ( int )); However, here: void foo ( void * vptr ) { } int main () { int * p = ( int *) malloc ( sizeof ( int )); foo ( p ); return 0 ; } Both C++ and C compile it with no complain. Why?
Sum of four elements equals X
- Get link
- X
- Other Apps
By
Admin
-
Given an array of integers, find all combination of four elements in the array whose sum is equal to a given value X. For example, if the given array is {10, 2, 3, 4, 5, 9, 7, 8} and X = 23, then your function should print “3 5 7 8″ (3 + 5 + 7 + 8 = 23). Note: Numbers should not be overlapping. eg(3,5,7,4) will generate 3+5=8 and 5+7=12 , for sum equals 20, 5 is overlapping.
Exchange gold coins
- Get link
- X
- Other Apps
By
Admin
-
In a monetary system each coin has an integer number written on it. A coin ' n ' can be exchanged in a bank into three coins: n/2 , n/3 and n/4 . But these numbers are all rounded down. You can also sell coins for dollars and their exchange rate is 1:1. You have one gold coin. What is the maximum amount of dollars you can get for it? eg: for a coin with value 120 you can get 144 dollars. Suggest an algorithm to solve the problem.