Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using codepad.org, using any language except for C/C++ do the following: Functio

ID: 3569706 • Letter: U

Question

Using codepad.org, using any language except for C/C++ do the following:

Function gcd returns the greatest common divisor of two integers. Write (or Google) the recursive function that implements Euclid's algorithm:

int GCD(int x, int y) {
if (y==0) return x;
else return GCD(y, x % y);

gcd (9,18);

gcd(16,25);

gcd(27,81);

gcd(36,81);

Function biggest returns the largest number in a list.

Function positive returns a list consisting of the positive numbers in a list

Function intersect returns the intersection of two lists.

Show examples that properly demonstrate these functions

Explanation / Answer

def HCF(a,b):
   if (b == 0):
       return a
   return HCF(b,a%b);
  
def biggest(l):
   max = -1000
   for ele in l:
       if (ele > max):
           max = ele
   return max
  
def positive(l):
   t = []
   for ele in l:
       if (ele > 0):
           t.append(ele)
   return t

def intersect(l,b):
   t = []
   for ele in l:
       if ele in b:
           t.append(ele)
   return t

print 'biggest number in the list'  
print biggest([12,14,11,6,4,2,5,1]);
print ' list of positive numbers'
print positive([-1,-5,-7,9,1,3,-4,-8,2]);
print ' intersection of two list'
print intersect([1,2,3],[2,3,4,5])

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote