Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program called factoral.c is listed at the end of these notes. This program calculates the factorial of a number. Factorials: Eight factorial means 8.7-6-5-4-3-2-1

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
The program called factoral.c is listed at the end of these notes. This program calculates the factorial of a number. Factorials: "Eight factorial" means 8.7-6-5-4-3-2-1 For short this is written as 8! "Five factorial" would be 5! or 5.-4.3.2.1 = 120. Some other factorials would be: 4! = 4.3.2.1 "four factorial" 3! = 3-2-1 "Three factorial" 2! = 2.1 1! = 1 We keep multiplying by smaller and smaller integers until we reach one. Since we count down, a negative integer is not allowed. Also 0! is defined as 1 for mathematical reasons. In Microsoft Visual C++, we will run the Debug facility to trace values of the variables. You will build a "watch table" which can list variables In Microsoft Visual C++, we will run the Debug facility to trace values of the variables. You will build a "watch table" which can list variables and their values. First, run the program by choosing Debug\Step Into. One line will be pointed by a yellow arrow at a time. The compiler is about to process this line. You can move through the program line by line by pressing the F11 key. Whenever the control goes into a built-in function, click Debug| Step Out to go back to the source code. Next, we have to make a watch table of variables. A variable is added to the watch table by the following steps: (1) Choose Debug\Quick Watch. (2) Enter a variable like "num" in the Expression: and click "Add Watch" (3) Repeat for the other variables: n, k, product and result (4) Click Close Now the variables will appear in the watch window Watch1 at the bottom of the screen. (1) What is the first line pointed by the yellow arrow? 12:55 7 Lab #1 DOCX-24 KB WISCING Now the variables will appear in the watch window Watch at the bottom of the screen. (1 4.) What is the first line pointed by the yellow arrow? (2) What is the initial value of num after it is declared? (3) What is the initial value of result after it's declared? (4) What are the values of the local variables of the function fact() at this point before calling fact /? (k. n, product) (5) When the fact() function is called, what happens to the value of num? (6) What are the initial values of k., and product when the function fact() is called? (7) What happens to n, k, and product when control returns to main()? (8) Check what part of the program cach variable is defined? product Section Completed and witnessed by Instructor Open Office 9 A combination of Cim.. mans how many ways you can pickn obiects from mobiects. For instance it you had poker cards and 12:55 7 Lab #1 DOCX - 24 KB VOGLIFORUMS oyu Part 22 marks) A combination of C(m,n) means how many ways you can pick m objects from m objects. For instance if you had 5 poker cards, and chose 3 of them, then the number of ways of picking them would be C(5.3). The formula is Cm.n) - m! written as 3 factorials n! (m-n)! For the cards we would have: (5.3) - 5 -120.- 120 - 10 3! (5-3)! 6-2! 12 You could have 10 different combinations, Write a program that asks for the number of cards to choose from, m, and the number of cards to pick, n. Next calculate the number of combinations by calling the fact function for each factorial Section Completed and witnessed by Instructor Open Office 92 Program Factoral.e to calculate the factorial of 12:55 7 X Lab #1 DOCX - 24 KB /* Program factoral.e to calculate the factorial of an Integer number entered from the keyboard * #define _CRT_SECURE_NO_WARNINGS #include #include /* needed by system) long fact(int n); /* function prototype / int main(void) int num; long results system("CLS"); printf("what is the number for factorial > scant("d", &num); result - fact (num) printf("d! is sids", num, result); system("pause"); return 0; 1 long fact (int n) 1 long product - 1/records factorial Ant k; /Index / If ((n-1) 1 (n=0) /* handle special cases / return 11 if in

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions