1) In mathematics, a factorial of a number is calculated by multiplying that number by all of the successive values less than it, stopping at 1. For example, factorial of 4 is written 4! and calculated as: 4! = 4 * 3 * 2 * 1 = 24 2) Write a program consisting of two functions (plus the main function). The first function should read in a number and then return this value back to the main function. This value should then be passed as a parameter (by value) into the second function which calculates and displays the factorial. Note: validate the input value (in the first function) to be greater than 1. 3) Improve your program from question 2, by changing the second function (that calculates the factorial) so that the result is returned to the main function instead of being printed where it is calculated. A new display function should be created and called from the main function that displays the calculated value. 4) Write a program that reads in two numbers and stores them into two variables a and b These values should then be passed into a function that swaps the values stored in the two variables (hint: use a temporary local variable). The values of the two variables should then be printed out (but not in the function where they are swapped). Note: you should use separate functions for each of the major steps in this program (i.e. input, processing, output). Remember, if you wish to pass two values out of a function, you will need to use pass by pointer parameters.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.2: Returning A Single Value
Problem 13E
icon
Related questions
Question

1) In mathematics, a factorial of a number is calculated by multiplying that number by all of the successive values less than it, stopping at 1. For example, factorial of 4 is written 4! and calculated as:

4! = 4 * 3 * 2 * 1 = 24

2) Write a program consisting of two functions (plus the main function). The first function should read in a number and then return this value back to the main function. This value should then be passed as a parameter (by value) into the second function which calculates and displays the factorial. Note: validate the input value (in the first function) to be greater than 1.

3) Improve your program from question 2, by changing the second function (that calculates the factorial) so that the result is returned to the main function instead of being printed where it is calculated. A new display function should be created and called from the main function that displays the calculated value.

4) Write a program that reads in two numbers and stores them into two variables a and b These values should then be passed into a function that swaps the values stored in the two variables (hint: use a temporary local variable). The values of the two variables should then be printed out (but not in the function where they are swapped). Note: you should use separate functions for each of the major steps in this program (i.e. input, processing, output). Remember, if you wish to pass two values out of a function, you will need to use pass by pointer parameters.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Knowledge Booster
Types of 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++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
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