Solved

GCD (LISP)

Posted on 2004-04-25
6
1,298 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 9

Expert Comment

by:ankuratvb
ID: 10912054
0
 
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 40 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

776 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