You cannot copy content of this page.

Program to compute GCD of given two numbers x and y

Program to compute GCD of given two numbers x and y



Recursion

Program to compute GCD of given two numbers x and y

#include <stdio.h>
#include <conio.h>

/*Recursive function to compute GCD*/
int GCD(int x,int y)
{
if(y==0)
return x;
else if(x<y)
return GCD(y,x);
else
return GCD(y,x%y);
}



void main()
{
int x,y,res;
clrscr();
printf(“nEnter first number?”);
scanf(“%d”,&x);
printf(“nEnter second number?”);
scanf(“%d”,&y);
res=GCD(x,y);
printf(“nGCD of %d and %d is %d”,x,y,res);
getch();
}



Comments are closed
x Close

Like Us On Facebook