• C

# GCD (LISP)

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
###### Who is Participating?

x

Commented:
LISP, C, what's the difference? :)

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

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

pass in 2 numbers.
0

Commented:
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 Commented:
I am intrested in having the code in LISP language. I am new to LISP programming. Please help me.
0

Commented:
0

Commented:
BTW,this is the C programming TA.
You should post these questions in either Programming Languages or the Programming TA.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.