Jump to content
Fórum Script Brasil
  • 0

Xlisp - Divisão


beuleal

Question

Olá amigos, estu estudando Xlisp, porem estou com dificuldades em realizar uma funcao de divisao, por enquanto somente com positivos.

Segue meu cod:

(defun div(x y)
    (cond ((equal x 0) (equal y 0) 0)
          ((equal x y) 1)
          ((equal y 1) x)
          ((equal x 0) 0)
          ((equal y 0) 0)         
          ('t (soma(div (subt (x y)) y) +1))))
          
(defun negativo (x)
    (cond ((equal x 0) 'nil)
          ('t (neg x x))))

(defun neg (a d)
    (cond ((equal a 0) 't)
          ((equal d 0) 'nil)
          ('t (neg (1+ a) (1- d)))))

(defun soma (x y)
    (cond ((equal y 0) x)
          ((negativo y) (soma (1- x) (1+ y)))
          ('t (soma (1+ x) (1- y)))))

(defun subt (x y)
    (cond ((equal y 0) x)
          ((negativo y) (subt (1+ x) (1+ y)))
          ('t (subt (1- x) (1- y)))))

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...