C program to Find the GCD (Greatest Common Divisor) of two numbers

C program to Find the GCD (Greatest Common Divisor) of two numbers

GCD of Numbers in C, C Assignment to find GCD in C, C Language program to find GCD




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

void main()
{
int x,y;
clrscr();
printf("\nEnter two numbers :");
scanf("%d %d",&x,&y);
if(x==0 && y==0)
printf("\n No GCD");
else
if(x==0 && y!=0)
printf("GCD is %d",y);
else
if(x!=0 && y==0)
printf("GCD is %d",x);
else
{
while(x!=y)
{
if(x>y)
x=x-y;
else
if(x < y)
y=y-x;
}
printf("\n GCD is %d",x);
}
}

No comments:

Post a Comment