(defun fact (n)
(do
((i 1 (+ 1 i))
(prod 1 (* i prod)))
((equal i n) prod)))
I have done the code above and when i try, fact(4), it give me ans is 6. I am not sure what is going wrong. Can anyone help me?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Change to
Basically, you were doing one iteration less than necessary.