From the course: C Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Solution: Template factorial

Solution: Template factorial - C Tutorial

From the course: C Essential Training

Solution: Template factorial

(bright music) - The challenge for this chapter was to create a template function for the non-recursive factorial challenge from chapter six. Here's my solution. This is 08 solution from chapter eight of the exercise files. Notice that the code in the function block is exactly the same. Nothing here needed to change. All that needed to change was to put it in a template, create a template placeholder and use that for the type of the argument. Everything else remains the same here. So here we call it with an integer. We call it with a long long unsigned int. Call it with a long double. And when I build and run, you notice our results. Five factorial, 15 factorial. With the long double, we can even do 25 factorial, which has an exponent of 25 places. In this challenge, you've used your understanding of templates to create a templates-based solution for the non-recursive factorial function. I hope you can see how…

Contents