The Wayback Machine - https://web.archive.org/web/20240123092313/https://www.geeksforgeeks.org/arithmetic-operators-in-lisp/
Open In App
Related Articles

Arithmetic Operators in LISP

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, and division.

There are 7 arithmetic operators in LISP that are listed in the below table:

Operator Syntax Description
Addition Operator(+) + num1 num2 Add the two numbers
Subtraction Operator(-) – num1 num2 Subtract the second number from the first number
Multiplication(*) * num1 num2 Multiply two numbers
Division(/) /  num1 num2 Divide the two numbers
Modulus(mod)  mod num1 num2 Get the remainder of two numbers
Increment(incf) incf  num value Increment number by given value
Decrement(decf) decf num value Decrement number by given value

Example 1: LISP Program that demonstrates arithmetic operators

Lisp




;set value 1 to 300
; set value 2 to 600
(setq val1 300)
(setq val2 600)
  
;addition operation
(print (+ val1 val2))
  
;subtraction operation
(print (- val1 val2))
  
;multiplication operation
(print (* val1 val2))
  
;division operation
(print (/ val1 val2))
  
;modulus operation
(print (MOD val1 val2))
  
;increment a by 10
(print (incf val1 val2))
  
;decrement b by 20
(print (decf val1 val2))


Output:

900  
-300  
180000  
1/2  
300  
900  
300 

Example 2:

Lisp




;set value 1 to 30
; set value 2 to 15
(setq val1 30)
(setq val2 15)
  
;addition operation
(print (+ val1 val2))
  
;subtraction operation
(print (- val1 val2))
  
;multiplication operation
(print (* val1 val2))
  
;division operation
(print (/ val1 val2))
  
;modulus operation
(print (MOD val1 val2))
  
;increment a by 10
(print (incf val1 val2))
  
;decrement b by 20
(print (decf val1 val2))


Output:

45  
15  
450  
2  
0  
45  
30 

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!


Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 21 Sep, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials