首页 资讯 科技 财商 汽车 家电 文娱 生活
首页 > 科技

代写Algorithm for GCD

2024-04-15 作者:code


Programming Assignment 6
There are 2 parts to this assignment, both of which should be implemented in one single menubased program. Do not submit 2 .asm files.
Description:
You will write a program that presents the user with a menu. That menu will provide 3 choices as
defined below.
Main menu
----------------------------------------------
1. Display all primes between 2 and n (max of 10000)
2. Euclid’s Algorithm for GCD
3. Exit
Note: The user must always be prompted for input. All inputs must be error checked.
Part 1(20 points):
1. Write a procedure (GetInt) that accepts an unsigned integer from the user and verifies that the
number is a valid input. It must be in the range 2 to 10000 (inclusive).
2. Write a procedure (FindPrimes) that calculates all prime numbers between the 2 and the user
input integer n.
a. Use the Sieve of Eratosthenes to find all primes between 2 and n. There are many examples
of this online, and pseudocode provided below.
b. Display your results using the procedure PrintResults, outlined in step 3.
c. Do not simply hardcode an array of primes, no credit will be given if this is done. They must
be calculated.
3. Write a procedure (PrintResults) that displays: (1) how many primes are in the range of 2 to n and
(2) lists all primes in the following format. Do not use dumpmem. There should be 7 prime
numbers per line, with the possible exception of the last line. Ensure that your numbers line up
in columns as shown below. A string of 5 spaces will not work.
Example: User input n=25
4. Your program will run using a menu procedure (MainMenu), make sure to check for valid input.
5. After displaying the results of a procedure, pause and wait for a key press to continue.
6. Display the Main Menu each time the user elects to stop the current procedure. Meaning each
time a number is entered, primes are displayed, wait for a keypress to acknowledge this, and ask the
user if they would like to input another number or return to the main menu.
Pseudocode for the Sieve of Eratosthenes
Start with a boolean array is_prime of an appropriate size, all initialized to
true (1).
For each i from 2 to 5000, do
If is_prime[i] is true,
For each m from i2 to 5000, step i
set is_prime[m] to false (0)
Part 2(20 points):
Write a recursive implementation of Euclid’s Algorithm for finding the greatest common divisor
(GCD) of two integers. You can find pseudocode for this algorithm online(be sure to cite in your
program where you found pseudocode if any is used). The output shall be of the following format:
Specifications:
1. Do not use USES.
2. Error check after each input. All numbers should be unsigned in part 1, part 2 may use
signed numbers. No number greater than 10000 should be entered.
3. Do not use any . directives(.if, .while, .else, etc.).
4. You must use a recursive algorithm for part 2.
5. Remember your procedures should accomplish a basic task, so you may write more
procedures than just those outlined above.
6. Pass variables to procedures using the Stack. Variables are placed on the stack before
calling the procedure.
7. Remember that you can create local variables, but they are scoped to the procedure they
are defined in.
8. All labels must be unique. This includes data labels and code labels. Do not reuse labels.
9. Style is important. Write clean readable code with sufficient commenting.
10. Make sure your program compiles before submitting it.

请加QQ:99515681  邮箱:99515681@qq.com   WX:codinghelp

网站地图

Copyright © 2024 吉新网 All Rights Reserved.

本站部分内容来源于用户投稿,内容相关请联系Q:230098551