lisp code to find sum of n numbers-programmingraja

  

Aim: Write to lisp code to find sum of n numbers. (Using iteration) (Using function)

Software Used: Gnu Common LISP

coding:

>(defun sum-list (numbers)

(if null numbers ) 0

(+ (first numbers) (sum-list (rest numbers)))))


SUM-LIST


> (sum-list '(5 4 6 2))


17


>(defun sum-n-numbers( & rest nums)

(loop for num in nums summing num))


SUM-N-NUMBERS


>(sum-n-numbers 5 4 6 2)

17

OUTPUT :





Post a Comment

0 Comments