• 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
rmvprasadAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
NovaDenizenConnect With a Mentor Commented:
LISP, C, what's the difference? :)

(defun gcd (a b)
    (cond
      ((eq b 0) a)
      (t (gcd b (% a b)))))
0
 
hongjunCommented:
GCD
---
    int gcd(int a, int b) {
          if (a == 0)
                return b;
          else
                return gcd(b % a, a);


pass in 2 numbers.
0
 
hongjunCommented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

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

All Courses

From novice to tech pro — start learning today.