![]() |
|
#1
|
|||
|
|||
Please help me just get startedHere I go again this class is killing me, the instuctor is a nice guy and all is's just he really doesn't explain things well. This is what I have to do and I can't get started. The problem is there are no examples at all on factorial programs in the book and all the instuctor does is show a Power Point at the beginning of class and then gives us this and says now write this. I know it's very elementry I'm just not getting it.
1.) Write a program using FOR control statement to print the factorial of a number n. Factorial of positive number n in n*(n-1) *(n-2) *(n-3)... For example: Factorial of 5 is ( 1*2*3*4*5) = 20 Factorial of 4 is ( 1*2*3*4*5) = 24 2.) Your program should do the following a. Ask the user to enter a positive integer. b. Read the integer and print out the factorial of the number. c. Ask the user if he/she wants to coninue. d. If yes, repeat steps a,b,c, if no quit the program. |
|
#2
|
|||
|
|||
Re: Please help me just get startedThe structure of a for loop is
Code:
For factorial, it looks like you need to declare a variable outside the loop to hold the factorial, then loop from 1 (initialize i to 1) up to the number (the condition could be "i < number" and in the loop multiply the factorial by i. Note that your examples are incorrect. They should read Factorial of 5 is ( 1*2*3*4*5) = 120 Factorial of 4 is ( 1*2*3*4) = 24 Once you've tackled the factorial part, work on the continue part. (Very) slightly more advanced: since the multiplicative identity property says that n*1==n, always and forever, can you optimize the loop? |
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to make my program get started along with the windows startup | rangamma | Java Forum | 0 | 26-Apr-2006 02:41 |
| Using C++ for gfx (was Need help to get started.) | Nick | C++ Forum | 3 | 21-Mar-2005 03:18 |
| getting started | Lamefif01 | MS Visual C++ / MFC Forum | 4 | 10-Feb-2005 23:15 |
| Our very special offers started!! | abc5net | Web Hosting Advertisements & Offers | 0 | 15-Jul-2003 11:24 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The