1. Create a new program called Lab9A that will calculate the factorial for a number. a....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Create a new program called Lab9A that will calculate the factorial for a number. a. Create an int function named calcfactorial that receives an integer parameter (x) and will return the factorial for x. To compute a factorial for x, you would follow the pattern shown: = x * x-1 * x-2 *....* 2 * 1 (Ex- The factorial for 5 would be 5*4*3*2*1 which = 120) b. Create a void function named printResult that accepts 2 integer parameters (the original number & its factorial) and prints both on the same line as shown: The factorial of 5 is 120 C. In the main function: i. Declare 2 int variables: n and f ii. Ask the user to enter the value of n iii. Call calcFactorial sending n as the parameter and placing the returned value into f. iv. Then we will call printResult sending n and fas parameters. It does not return anything. Compile and test your program. If you enter 5 when it runs, the result should be 120. If you type 6 when it runs, the result should be 720. 2. Create a new program called Lab9B that will create a multiplication table for an input number. a. Create an integer function named getNumber (with no parameters) . ii. iii. b. Create a void function called printTable that will accept an integer as a parameter and will print out a multiplication table for that number like the example below. You need to use a loop to do this. (If the input number is 7) 1 It should ask the user to enter a positive integer between 1 and 10. In the function write a while loop that will keep asking for a number until the user enters one that meets the requirements. Then return the number. C. 2 3 4 5 6 7 8 9 10 7 14 21 28 35 42 49 56 63 70 (Basically it's printing the number ... tab... 1 number * then number... tab... 2 * number ************* and so on......until 10 * number In the main function, call getNumber and put its returned value into an int variable. (to get the number for your multiplication table) d. Then call printTable (sending the returned number from getNumber as the parameter) to print it the multiplication table. e. Don't forget your prototypes for both functions at the top of your program. 3. Write a new program named Lab9C that will ask the user for an integer value and add up all the odd numbers between 1 and that value. a. After the main function, create a void function named addOdds that accepts one int parameter named num. b. The function should follow the flowchart below to calculate and print the desired value. (Remember, you need to declare total inside the function, but num is the parameter, so you won't redeclare it in the function - it gets declared inside the () in the function's heading.) Back in the main method, ask the user for an integer. C. d. Call the addOdds function sending that integer as the parameter. e. Don't forget your prototype. -0-0 print total Stop No No 10 Start total = 0 num> 0? Yes (if) num is odd? (while loop) subtract 1 from num Yes add num to total 4. Write a new program called Lab9D. In this program you will ask the user for a positive integer and print out each even digit in it (in reverse order). Sample Test Cases: The input 1526 would print 62. The input 18940 would print 048. a. After the main function, create a void function named printDigits that accepts one int parameter named num. b. The function should follow the flowchart below to print the even digits of num in reverse order. C. Back in the main method, ask the user for an integer. d. Call the printDigits function sending that integer as the parameter. e. Don't forget your prototype. Use the following flowchart to write your printDigits function. (num & digit are int variables.) Stop No No Start num > 0? Yes digit = num % 10 digit % 2 = 0? num= num/10. Yes Print digit 1. Create a new program called Lab9A that will calculate the factorial for a number. a. Create an int function named calcfactorial that receives an integer parameter (x) and will return the factorial for x. To compute a factorial for x, you would follow the pattern shown: = x * x-1 * x-2 *....* 2 * 1 (Ex- The factorial for 5 would be 5*4*3*2*1 which = 120) b. Create a void function named printResult that accepts 2 integer parameters (the original number & its factorial) and prints both on the same line as shown: The factorial of 5 is 120 C. In the main function: i. Declare 2 int variables: n and f ii. Ask the user to enter the value of n iii. Call calcFactorial sending n as the parameter and placing the returned value into f. iv. Then we will call printResult sending n and fas parameters. It does not return anything. Compile and test your program. If you enter 5 when it runs, the result should be 120. If you type 6 when it runs, the result should be 720. 2. Create a new program called Lab9B that will create a multiplication table for an input number. a. Create an integer function named getNumber (with no parameters) . ii. iii. b. Create a void function called printTable that will accept an integer as a parameter and will print out a multiplication table for that number like the example below. You need to use a loop to do this. (If the input number is 7) 1 It should ask the user to enter a positive integer between 1 and 10. In the function write a while loop that will keep asking for a number until the user enters one that meets the requirements. Then return the number. C. 2 3 4 5 6 7 8 9 10 7 14 21 28 35 42 49 56 63 70 (Basically it's printing the number ... tab... 1 number * then number... tab... 2 * number ************* and so on......until 10 * number In the main function, call getNumber and put its returned value into an int variable. (to get the number for your multiplication table) d. Then call printTable (sending the returned number from getNumber as the parameter) to print it the multiplication table. e. Don't forget your prototypes for both functions at the top of your program. 3. Write a new program named Lab9C that will ask the user for an integer value and add up all the odd numbers between 1 and that value. a. After the main function, create a void function named addOdds that accepts one int parameter named num. b. The function should follow the flowchart below to calculate and print the desired value. (Remember, you need to declare total inside the function, but num is the parameter, so you won't redeclare it in the function - it gets declared inside the () in the function's heading.) Back in the main method, ask the user for an integer. C. d. Call the addOdds function sending that integer as the parameter. e. Don't forget your prototype. -0-0 print total Stop No No 10 Start total = 0 num> 0? Yes (if) num is odd? (while loop) subtract 1 from num Yes add num to total 4. Write a new program called Lab9D. In this program you will ask the user for a positive integer and print out each even digit in it (in reverse order). Sample Test Cases: The input 1526 would print 62. The input 18940 would print 048. a. After the main function, create a void function named printDigits that accepts one int parameter named num. b. The function should follow the flowchart below to print the even digits of num in reverse order. C. Back in the main method, ask the user for an integer. d. Call the printDigits function sending that integer as the parameter. e. Don't forget your prototype. Use the following flowchart to write your printDigits function. (num & digit are int variables.) Stop No No Start num > 0? Yes digit = num % 10 digit % 2 = 0? num= num/10. Yes Print digit
Expert Answer:
Related Book For
Numerical Methods For Engineers
ISBN: 9780071244299
5th Edition
Authors: Steven C. Chapra, Raymond P. Canale
Posted Date:
Students also viewed these databases questions
-
Q1. You have identified a market opportunity for home media players that would cater for older members of the population. Many older people have difficulty in understanding the operating principles...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
The $1.6 Billion Mega-millions winning lottery ticket is based upon the total amount of cash received if the annuity option is taken. The cash prize is $913,700,000 which you get immediately. The...
-
Sherrill Company completed the following transactions: 2015 Jan. 9 Sold merchandise on account to Rick's Supply, $1,600. Jan. 15 Wrote off the account of Pete Redding as uncollectible because of his...
-
Differentiate between financial and management accounting. Give an example of how management accounting reports would be incorporated into financial accounting reports.
-
For a normal probability density function, \(\operatorname{Prob}[-3 \sigma \leq x(t) \leq 3 \sigma]\) is a. 0.6827 b. 0.999937 c. 0.9973
-
The management of Ballard MicroBrew is considering the purchase of an automated bottling machine for $120,000. The machine would replace art old piece of equipment that costs $30,000 per year to...
-
Use g=10m/s 1. The figure shows a potential energy diagram for a particle moving along the x-axis. The particle is at rest at point A and is then given a slight nudge to the right. Describe the...
-
(a) What is the sampling distribution for the difference in two sample means? What are the conditions for the sampling distribution of the difference of two sample means to be approximately normal?...
-
A prion is a disease-causing agent composed of a. cells. b. nucleic acid with a protein coat. c. protein alone. d. nucleic acid alone.
-
In addition to the use of T-DNA vectors, other methods to produce transgenic plants include a. biolistic gene transfer. b. microinjection. c. electroporation. d. all of the above.
-
Which of the following best describes the approach that was used in the first gene therapy trial for treating SCID? a. The normal ADA gene was introduced by injecting liposomes directly into the...
-
Which of the following would not be consistent with the idea that a disorder has a genetic component? a. The disorder is more likely to occur among an affected persons relatives than in the general...
-
During the molecular process of homologous recombination between homologous chromosomes, a. a Holliday junction forms. b. branch migration occurs. c. a heteroduplex region forms. d. all of the above...
-
The Vintage Car Parts Company of Elko Nevada was closed on January 1 st for New Years Day and stayed closed on January 2 nd in order to take a complete physical inventory. At the conclusion of the...
-
Suppose that fraction used = / 1.0 + 0.1Mt. for some parameter 1. Write the discrete-time dynamical system and solve for the equilibrium. Sketch a graph of the equilibrium as a function of ....
-
Solve the following problem with the fourth-order RK method: d2y/dx2 + 0.6 dy/dx + 8y = 0 where y(0) = 4 and y(0)= 0. Solve from x = 0 to 5 with h = 0.5. Plot your results.
-
Develop, debug, and test a program in either a high-level language or macro language of your choice to generate the transpose of a matrix. Test it on the matrices from Prob. 9.3.
-
An experiment is performed to define the relationship between applied stress and the time to fracture for a type of stainless steel. Eight different values of stress are applied, and the resulting...
-
Identify at least four methods by which investors and/or the entrepreneur in a new venture can harvest their investment in a new venture. Describe the costs and benefits of each, and provide a...
-
What are the key distinctions between corporate finance and entrepreneurial finance?
-
Explain what underpricing is and review the various explanations for why it might occur. How does underpricing figure into the cost of going public?
Study smarter with the SolutionInn App