Question

I. (20 points) Find the gcd for the following two problems; use the pseudo code. int main GCD (a,b) int gcd 0 if (a 0) OR (b 0) return gcd if (b a) return gcd r mod (r1, r2) while r 0 r mod (r1, r2) if (r 0) {gcd r2 safety return gcd Problem 1 (10 points) Problem 2 (10 points) a 1298 b 561 r mod 1, a 1534 b 663 Tr mod(r1,r2) rz) rl r2 r1
0 0
Add a comment Improve this question Transcribed image text
Answer #1

rmod(r1,12) -1534 a 1298 r1 561 176 b-561 r2 176 rrmod r1,r2) r1 663 209 39 r2 208 39 13 39 13 0 0

The GCD values of 2 sets are

GCD(1298, 561) - 11

GCD(1534, 663) - 13

Add a comment
Know the answer?
Add Answer to:
Find the gcd for the following two problems; use the pseudo code. int main GCD (a,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following C codes to compute the gcd of two integers. /// code 1 #include...

    Consider the following C codes to compute the gcd of two integers. /// code 1 #include <stdio.h> int gcd(int a, int b) {     while (a != b) {         if (a > b) a = a - b;         else b = b - a;     }     return a; } /// code 2 #include <stdio.h> int getint() {     int i;     scanf("%d", &i);     return i; } void putint(int i) {     printf("%d\n", i); } int main()...

  • Look at the following pseudo code: Binary_search(int a[], int size) { ……….// binary search and return...

    Look at the following pseudo code: Binary_search(int a[], int size) { ……….// binary search and return } Selection_Sort(int a[], int z) { …..// do the selection sort } main() {     Selection_Sort(array, size);     Binary_Search(array, item); } Calculate the time complexity of this code and use O() notation.

  • c++ 4) Look at the following pseudo code: Binary..search(int a[], int size) { } wel binary...

    c++ 4) Look at the following pseudo code: Binary..search(int a[], int size) { } wel binary search and return Selection Sort(int a[], int z) { ww/ do the selection sort } main { Selection Sort(array, size): Binary. Search(array, item): IS Calculate the time complexity of this code and use 0 ) notation. +12 fa 11.

  • This code needs to be written in Assembly language using Keil uvision 5. Please use Keil...

    This code needs to be written in Assembly language using Keil uvision 5. Please use Keil Assembler. Or ARM assembly. Thanks. int main(void) { // initializing int R0 = 5; int R1 = 10; // for loop addition with CMP while(RO <=| 10) R$++; // for loop subtraction without CMP#10 while(R1 > 0) R1--; // if else statement if (RO > 0) R0 = 10; R1 = 10; else | R0 = 20; R1 = 30; // must using branching...

  • its brr[8] (40%) Convert the following C-pseudo code into MIPS assembly code as a standalone program...

    its brr[8] (40%) Convert the following C-pseudo code into MIPS assembly code as a standalone program (including main and all the required directives). You can use any register. You must comply, however, with the convention of register usage. Before writing your code perform an explicit register allocation phase. Note that the C snippet is int arr[8]; int brr[4]-{1, 2, 3, 4, 5, 6, 7, 8) int i-8; while (i>-0) arrli]-brr[i-); (40%) Convert the following C-pseudo code into MIPS assembly code...

  • Given the following pseudo code: int result; (result is 1 byte) int count; (count is 1...

    Given the following pseudo code: int result; (result is 1 byte) int count; (count is 1 byte) for (result= 10, count= -10; count < result ; count++) { if(count > 2) result--; else result ++; } 1) write an assembly language program that will implement this pseudo code using a while construct. 2) write an assembly language program that will implement this pseudo code using a do-until construct Note: For both 1) and 2), do not forget to include the...

  • Consider the problem of finding the Greatest Common Divisor (GCD) of two positive integers a and...

    Consider the problem of finding the Greatest Common Divisor (GCD) of two positive integers a and b. It can be mathematically proved that if b<=a GCD(a, b) = b, if (a mod b) = 0; GCD(a, b) = GCD(b, a mod b), if (a mod b) != 0. Write a recursive function called GCD with signature “public static int GCD(int a, int b)” that returns the greatest common divisor of two positive integers a and b with b <= a....

  • Find out what the following assembly code calculates AREA my code, CODE EXPORT main ALIGN ENTRY...

    Find out what the following assembly code calculates AREA my code, CODE EXPORT main ALIGN ENTRY main PROC MOVS MOVS MOVS r0,#0 r1,#15 r2,#0 loop CMP BGT MLA ADDS r2,r1 stop re,r2,r2,ro r2,r2,#1 loop % The final result is saved in register r0 stop B stop ENDP END

  • Write a recursive method in java to find GCD of two integers using Euclid's method. Integers...

    Write a recursive method in java to find GCD of two integers using Euclid's method. Integers can be positive or negative. public class Recursion {                 public static void main(String[] args) {                                 Recursion r = new Recursion();                                 System.out.println(“The GCD of 24 and 54 is “+r.findGCD(24,54)); //6                 }                 public int findGCD(int num1, int num2){                                 return -1;                 } }

  • Write the branch-friendly pseudo code int i = 10; int sum = 0; while (i >=...

    Write the branch-friendly pseudo code int i = 10; int sum = 0; while (i >= 0) { sum = sum + i; i = i – 1; }

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT