1 Replies - 3623 Views - Last Post: 12 November 2009 - 05:03 PM Rate Topic: -----

#1 bombers  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • 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

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,436
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1