Home Uncategorized Find the GCD of two given integers using Non-Recursion Functions

Find the GCD of two given integers using Non-Recursion Functions

SHARE

Write a C program To find the GCD (Greatest Common Divisor) of two given integers using functions with Non- Recursion.

#include <stdio.h>
int GCD(int,int);
int main()
{
int a,b,c;
printf(“Enter two numbers :\n”);
scanf(“%d%d”,&a,&b);
if(a<b)
{
c=a;
a=b;
b=c;
}
c=GCD(a,b);
printf(“GCD of given number is: %d\n”,c);
return 0;
}
int GCD(int x,int y)
{
int t;
do
{
if(x%y==0)
return y;
else
{
t=x%y;
x=y;
y=t;
}
}while(x>y);
}

Output:

Enter two number:
98 63
GCD of given number is : 7

Write a C program To find the GCD (greatest common divisor) of two given integers using functions with Recursion.

Back to the programs list.