Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please see that picture Design another simple C++ function and add it to the .h

ID: 3543539 • Letter: P

Question

Please see that picture

Design another simple C++ function and add it to the .h file you prepared in the previous problem, P1. This function must accept one integer n as input, and return the number of trailing zeroes n! would have. For example if n=5, then, 5! = 120, therefore it has one trailing zero, and your function must return 1. Your design must be able to handle extreme input values for n, such as 4294967296 (which is, 232). Call this function from your main().Take a screenshot of the result and paste it in the PDF document. Factorial operation is defined as follows: HINT: This has a very simple solution that can be implemented with a single while ( ) loop. Integers get trailing zeros when multiplied by 10. Note that 10 = 5 Times 2. And, the 5! is the first integer factorial where a 5 Times 2 condition exists in the series. Therefore number of trailing zeros in n! is the sum of divides of n to the powers of 5, or summarily, the following series:

Explanation / Answer

// function prototype, add to .h file
unsigned factorialTrailingZeroes(unsigned n);

// function definition, add to .cpp file
unsigned factorialTrailingZeroes(unsigned n)
{
unsigned zeroes = 0;
for (unsigned k = 5; k <= n; k *= 5)
zeroes += n / k;
return zeroes;
}



example use: http://ideone.com/Vo3Ur3

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote