

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: INTRO TO COMPU ORGNZN; Subject: COMPUTER DESIGN/ARCHITECTURE; University: University of Florida; Term: Unknown 1989;
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Turn in one hardcopy printout per group of all code at the beginning of class on June 10th^ with all group members’ names and the title “CDA 3101 HW 2” at the top of the first page, clearly printed. An electronic version (ZIP) should also be submitted on eLearning by this time. Your work should be well commented and well formed as specified in the syllabus, and must conform to the standard MIPS conventions as presented in class. Correct output does not guarantee an A!
Please include the following for each applicable function:
Write a program that takes in an arbitrary number of unsigned integers as input and calculates their LCM ( l east c ommon m ultiple) by prime factorization. Use the provided prime factorization algorithm (below) to find each number’s factors. The quantity of integers and the integers themselves should be specified by the user. (For a reference, see http://en.wikipedia.org/wiki/Least_common_multiple.)
int* primeStart(int number) { return prime(number, 2, 0); }
int* prime(int number, int factor, int factorsFound) { if(factor * factor > number) //is sqrt(factor) < number? { //if so, number is prime. //(We’ve covered the other factors.) int* factors = new int[factorsFound+1]; factors[factorsFound] = number; return factors; } if(number % factor == 0) //% = modulus, remainder op { number = number / factor; //Factor may repeat (below) int* factors = prime(number, factor, factorsFound+1); factors[factorsFound] = factor; return factors; } else return prime(number, factor+1, factorsFound); }
A quick sidenote – since MIPS has two return value registers, you may wish to use the second register to hold the array length in the above two methods.