Page 1 of 1

help in need

Posted: Thu Oct 16, 2014 7:46 am
by PORCOREAL
need help to solve a problem in scheme that we have to call a procedure "enequa" that we gave a real number n and it calculate the product of the first n odd numbers if we gave it a number bellow 1 it gave us 1....
exemples :
(enequa 5) = 1x3x5x7x9 = 945
(enequa 1) = 1
(enequa -2) = 1
should start
(define (enequa n)

i need help because i have o know answer to this problem after my mondy test

Re: help in need

Posted: Fri Oct 17, 2014 1:55 pm
by Goheeca
You should've thought of it by yourself, it's pretty easy:

Code: Select all

(define (enequa n)
  (if (< n 1)
      1
      (* (if (odd? n) n 1)
         (enequa (- n 1)))))

Re: help in need

Posted: Thu Oct 23, 2014 8:58 am
by PORCOREAL
Yes...but we cant use "odd?". And I already solve that problem.

Now I have another doubt.
I have a bit of difficulty making those tables for iterative processes and needed help to make one for this problem:

Consider a procedure called "adder" that when we give a natural n ir returns the sum of all odd natural smaller than n if n is even and the sum of all natural pairs smaller than n where n is odd.

Sry for my english