Question: needed help writing the following recursive algorithm in maple?


Recursive algorithm for finding the sum of the first n odd positive integers.

 procedure   odd_sum n: positive integer )

    if   n = 1   then   return   1

    else   return   odd_sum ( n -1 ) + 2n -1

 

here's what I have but it doesn't work the way i want it?

mmm := proc (A::list) local k, i, sumofodd; if nops(A) = 1 then return 1 end if; for k to nops(A) do if type(A[k], odd) then sumofodd := 3*k-2 end if end do; sumofodd = sumofodd end proc

Please Wait...