Solved

# GCD (LISP)

Posted on 2004-04-25
1,338 Views
I am new to LISP programming. Could you please give me the code for
1) finding the GCD of two given numbers
2) Finding the square and square root of a given number
0
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 33

Expert Comment

ID: 10911610
GCD
---
int gcd(int a, int b) {
if (a == 0)
return b;
else
return gcd(b % a, a);

pass in 2 numbers.
0

LVL 33

Expert Comment

ID: 10911622
Complete code is this.

#include <stdio.h>
#include <math.h>

int square(int myint);
int gcd(int a, int b);

int main()
{
printf("%d\n", square(1));
printf("%lf\n", sqrt(9));
printf("%d\n", gcd(10,2));

return 1;
}

int square(int myint)
{
return myint*myint;
}

int gcd(int a, int b)
{
if (a == 0)
return b;
else
return gcd(b % a, a);
}

hongjun
0

Author Comment

ID: 10911882
I am intrested in having the code in LISP language. I am new to LISP programming. Please help me.
0

LVL 9

Expert Comment

ID: 10912054
0

LVL 9

Expert Comment

ID: 10912062
BTW,this is the C programming TA.
You should post these questions in either Programming Languages or the Programming TA.
0

LVL 22

Accepted Solution

ID: 10939402
LISP, C, what's the difference? :)

(defun gcd (a b)
(cond
((eq b 0) a)
(t (gcd b (% a b)))))
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
###### Suggested Courses
Course of the Month2 days, 16 hours left to enroll