Subscribe

RSS Feed (xml)

Monday, February 9, 2009

Write a C program to find the GCD (greatest common divisor) of two given integers using Recursive function.

#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(conio.h)
int gcd (int, int); //func. declaration.
void main( )
{
int a, b, res;
clrscr( );
printf("Enter the two integer values:");
scanf("%d%d", &a, &b);
res= gcd(a, b); // calling function.
printf("\nGCD of %d and %d is: %d", a, b, res);
getch( );
}
int gcd( int x, int y) //called function.
{
int z;
z=x%y;
if(z==0)
return y;
gcd(y,z); //recursive function
}

Note:- If u have any doubt regarding this program or logic, please feel free to contact me.

1 comment:

  1. What is the need of Google Translate in this page anna..

    ReplyDelete