help in need

Discussion of Scheme and Racket

help in need

Postby PORCOREAL » Thu Oct 16, 2014 7:46 am

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
Posts: 2
Joined: Thu Oct 16, 2014 6:53 am

Re: help in need

Postby Goheeca » Fri Oct 17, 2014 1:55 pm

You should've thought of it by yourself, it's pretty easy:
Code: Select all
(define (enequa n)
  (if (< n 1)
      (* (if (odd? n) n 1)
         (enequa (- n 1)))))
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.
User avatar
Posts: 271
Joined: Thu May 10, 2012 12:54 pm

Re: help in need

Postby PORCOREAL » Thu Oct 23, 2014 8:58 am

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
Posts: 2
Joined: Thu Oct 16, 2014 6:53 am

Return to Scheme

Who is online

Users browsing this forum: No registered users and 1 guest