Write a program to calculate composite numbers. First, the user is instructed to enter the number of composites to be displayed, and is prompted to enter an integer in the range [1 .. 400]. The user enters a number, n, and the program verifies that 1 n 400. If n is out of range, the user is reprompted until s/he enters a value in the specified range. The program then calculates and displays all of the composite numbers up to and including the nth composite. The results should be displayed 10 composites per line with at least 3 spaces between the numbers.
Requirements:
- The programmers name must appear in the output.
- The counting loop (1 to n) must be implemented using the MASM loop
- The main procedure must consist (mostly) of procedure calls. It should be a readable list of what the program will do.
- Each procedure will implement a section of the program logic, i.e., each procedure will specify how the logic of its section is implemented. The program must be modularized into at least the following procedures and sub-procedures :
- introduction
- getUserData
- validate
- showComposites
- isComposite
- farewell
- The upper limit should be defined and used as a constant.
- Data validation is required. If the user enters a number outside the range [1 .. 400] an error message should be displayed and the user should be prompted to re-enter the number of composites.
- The usual requirements regarding documentation, readability, user-friendliness, etc., apply. 8) Submit your text code file (.asm) to Canvas by the due date.
Notes:
- For this program, you may use global variables instead of passing parameters. This is a onetime relaxation of the standards so that you can get accustomed to using procedures.
- A number k is composite if it can be factored into a product of smaller integers. Every integer greater than one is either prime or composite. Note that this implies that
- 1 is not composite.
- The number must be positive.
- There are several ways to make your isComposite procedure efficient. (I recommend discussing this in your groups!)
- See next page for an example execution
page 1 of 2
Example (user input in italics):
Composite Numbers Programmed by Euclid
Enter the number of composite numbers you would like to see. Ill accept orders for up to 400 composites.
Enter the number of composites to display [1 .. 400]: 501 Out of range. Try again.
Enter the number of composites to display [1 .. 400]: 0 Out of range. Try again.
Enter the number of composites to display [1 .. 400]: 31
4 6 8 9 10 12 14 15 16 18
20 21 22 24 25 26 27 28 30 32
33 34 35 36 38 39 40 42 44 45 46
Results certified by Euclid. Goodbye.
Extra Credit:
- Align the output columns.
- Display more composites, but show them one page at a time. The user can Press any key to continue to view the next page. Since length of the numbers will increase, its OK to display fewer numbers per line.
- One way to make the program more efficient is to check against only prime divisors, which requires saving all of the primes found so far (numbers that fail the composite test). Its easy in a high-level language, but you will have to look ahead in the textbook to figure out how to do it in assembly language.
Reviews
There are no reviews yet.