From the course: C++ Essential Training
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Challenge: Non-recursive factorial - C++ Tutorial
From the course: C++ Essential Training
Challenge: Non-recursive factorial
(bright music) - [Instructor] Your challenge for this chapter is to create a non-recursive function for calculating factorials. Earlier in this chapter, we covered a recursive function that calculates factorials. This function is interesting and clever, but it has a serious flaw. Each iteration adds a function called the stack along with its parameters and return values. For large values of n, this can quickly overflow the stack causing crashes, errors and worse. The challenge is to create a non-recursive function to perform the same calculation. By way of refresher, the factorial of n is the product of all positive integers less than or equal to n. The purpose of this challenge is for you to create a function that takes a value and returns a value. It should take about 15 minutes, but it's okay if it takes longer or if you spend time experimenting and learning. And remember, your function should not use recursion.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.