Euclidean Algorithm to find GCD > C Program

Euclidean Algorithm to find GCD > C Program 

Cryptography and Network Security 


Program:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,x;
clrscr();
printf("Enter 1st Number ");
scanf("%d",&a);
printf("Enter 2nd Number ");
scanf("%d",&b);
x=gcd(a,b);
printf("GCD is %d",x);
getch();
}


int gcd(int x, int y)
{
int r1=x, r2=y, r, q;
if(r2==0)
return (r1);
else
while (r2>0)
{
q=r1/r2;
r=r1-q*r2;
r1=r2;
r2=r;
}
return(r1);

}

Output:

Comments

Popular posts from this blog

Intermediate Code Generation > C Program