# c programming; greatest common divisor; functions

Page 1 of 1

## 1 Replies - 4729 Views - Last Post: 12 November 2009 - 05:03 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=138686&amp;s=67ceae7e4ce33608ac2d0e4c1c8e1e1f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 bombers

• New D.I.C Head

Reputation: 2
• Posts: 2
• Joined: 27-October 09

# c programming; greatest common divisor; functions

Posted 12 November 2009 - 04:48 PM

C-programming using functions to find the GCD of 2 numbers.

The program won't run and it gave some exit error?? (this is on Kiss-C program)

```#include <stdio.h>
#include <kiss-compat.h>

int gcd (int x, int y);

int main (){

int integer1, integer2, answer;

printf("This program calculates the greatest common divisor of two integers.\n\n");

printf("Enter two integers:\t");
scanf("%d%d", &integer1, &integer2);

answer = gcd ( integer1, integer2);
printf("The greatest common divisor is: %d.\n", answer);

int gcd (int x, int y)
{
if(y == 0){
//printf("The GCD is: %f.\n", answer);
return x;
} else {
return gcd (y, (x%y));
}

}

}

```

Is This A Good Question/Topic? 0

## Replies To: c programming; greatest common divisor; functions

• Saucy!

Reputation: 6219
• Posts: 23,965
• Joined: 23-August 08

## Re: c programming; greatest common divisor; functions

Posted 12 November 2009 - 05:03 PM

You're defining your function WITHIN main. Do it outside of main.