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

ASAP Write pgms for these. Can all be in one program: #21, 22, 27, 28 ,29, 33 th

ID: 665526 • Letter: A

Question

ASAP Write pgms for these. Can all be in one program: #21, 22, 27, 28 ,29, 33

these are mini programs and here are the ones I have which are incorrect:, NONE of THESE are CORRECT!

#21

int digits(int x)

{

If (n==0)

Return 0;

Else

return 1+digit(x/10);

}

#22

#27

Void ReverseArray(ArrayType a, int first, int last)

{

If (first <= last)

{

Element tmp = a(last);

A(last) = a(first);

A(first) = tmp;

ReverseArray(a, first+1, last-1);

}

}

#28

Int sumArray(ArrayType a, int n)

{

Int sum =0 ;

For (int I=1, I <=n; i++)

{

Sum = sum + a(i)

}

Return sum;

}

#29

Int location (arrayType a, int first, int last, Element elm)

}

Int loc = 0;

For (int I = first; I <= last; i++)

If((i) == elm)

{

Loc = I;

Break;

}

}

Return loc;

}

#33

Int GCD(int a, int b)

{

If(a<0) a *= -1;

If(b<0) b *=1-;

If (a==0)

Return b;

Else if (b==0)

Return a;

Else {

Int rem = a%b;

Return GCD(b,rem);

}

}

Please help ASAP

RecursiveProblems.tiff - Windows Photo Viewer File Print E-mail Burn Open write recursive definitions of the functions whose prototypes are given in Exercises 27-29 27. void reverseArray (ArrayType a, int first, int last); /* Reverse the contents of alfirst], ..., a[last] 28, int surray(ArrayType a, int n); Return the sum of a[0], ..., a[n 1] * 29. int location(ArrayType a, int first, int last, Element elm); /* Return the location of elm in a[first], ..., a[last]. If not found, return 0.*/ 30. Using the basic string operations length, concatenate, copy, and find (see Section 5.2), develop a recursive algorithm for reversing a string 31. Proceed as in Exercise 30, but develop a nonrecursive algorithm 32. Write a recursive function that implements the algorithm in this section for determining if a number is a palindrome. 33. The greatest common divisor of two integers a and b, GCD(a, b), not both of which are zero, is the largest positive integer that divides both a and b. The Euclidean algorithm for finding this greatest common divisor of a and b is as fol lows: Divide a by b to obtain the integer quotient q and the remainder r,so that a tions f this bq + r (if b = 0, GCD(a, b) = a). Then GCD(a, b) = GCD(b, r). Replace a with b and b with r and repeat this procedure. Because the remainders are decreasing, eventually a remainder of 0 will result. The last nonzero remainder is GCD(a, b) For example, ative 1260 198-6+72 198 : 72-2 + 54 72 = 54-1 + 18 54-18 . 3 +0 GCD(1260, 198) GCD( 198, 72) = GCD(72, 54) ts in GCD(54, 18) 23 (Note: If either a or b is negative, replace them with their absolute values in this Page 4 of 4 5:59 PM 7/22/2015

Explanation / Answer

Note: Modifications highlight with bold.

21)

int digits(int x)

{

If (n==0)

return 0;

else                

return 1+digits(x/10); // letter 's' missing in function name

}

27)

void ReverseArray(ArrayType a, int first, int last)

{

while(first <= last)

{

int tmp = a(last);

a(last) = a(first);

a(first) = tmp;

ReverseArray(a, first+1, last-1);

}

}