C Program to find GCD of two numbers using recursion - c programs
what is GCD of two numbers
The greatest common divisor (gcd), also known as the greatest common factor (gcf), or highest common factor (hcf), of two or more non-zero integers, is the largest positive integer that divides the numbers without a remainder. For example, the GCD of 8 and 12 is 4.what is recurrsion
Functions are recursive if they call themselves. For this to work, the following conditions apply :•There must be a solveable problem.
•There must be a terminating clause.
write a c program to find GCD of two numbers using recursion
GCD of two numbers in / using c language
write a c program to find GCD of two numbers using recursion
GCD of two numbers in / using c language
#include<stdio.h>
#include<conio.h>
int GCD (int a,int b)
{
if (a<0) a= -a;
if (b<0) b= -b;
if (a==0 || b==1 || a==b) return b;
if (a==1 || b==0) return a;
if (a>b) return GCD (b, a%b);
else return GCD (a, b%a);
}
void main()
{
int x,y;
clrscr();
printf("nEnter 1st number:");
scanf("%d",&x);
printf("nEnter 2nd number:");
scanf("%d",&y);
printf("\nGCD is:%d", GCD(x,y));
getch();
}
No comments:
Post a Comment