Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

GCD (LISP)

Posted on 2004-04-25
6
Medium Priority
?
1,433 Views
Last Modified: 2012-06-27
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
Comment
Question by:rmvprasad
6 Comments
 
LVL 33

Expert Comment

by:hongjun
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

by:hongjun
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

by:rmvprasad
ID: 10911882
I am intrested in having the code in LISP language. I am new to LISP programming. Please help me.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Expert Comment

by:ankuratvb
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

by:
NovaDenizen earned 160 total points
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question