Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GCD (LISP)

Posted on 2004-04-25
6
Medium Priority
?
1,397 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
[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
  • Learn & ask questions
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
Technology Partners: 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!

 
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

Technology Partners: 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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

660 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