2- The factorial n! of a positive integer n is defined as n! = = 1*2*3 .. . * (n-1) * n Where 0! = 1 Write a function to calculate the factorial of a number. Argument: A number n of type unsigned int. Returns: The factorial n! of type long double. Write two versions of the function, where the factorial is calculated using a loop calculated recursively Test both functions by outputting the factorials of the numbers 0 to 20.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 15SA
icon
Related questions
Question
2- The factorial n! of a positive integer n is defined as
n!
= 1*2*3 . .. * (n-1) * n Where 0!
= 1
Write a function to calculate the factorial of a number.
Argument: A number n of type unsigned int.
Returns: The factorial n! of type long double.
Write two versions of the function, where the factorial is
• calculated using a loop
calculated recursively
Test both functions by outputting the factorials of the numbers 0 to 20.
Transcribed Image Text:2- The factorial n! of a positive integer n is defined as n! = 1*2*3 . .. * (n-1) * n Where 0! = 1 Write a function to calculate the factorial of a number. Argument: A number n of type unsigned int. Returns: The factorial n! of type long double. Write two versions of the function, where the factorial is • calculated using a loop calculated recursively Test both functions by outputting the factorials of the numbers 0 to 20.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr