//Program to find Gretest common divisor (GCD)
//using Euclidian algorithm.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c,k,d;
clrscr();
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
c=a%b;
printf("%d * %d = %d\n",a,b,c);
k=b<a?b:a;
while(c>0)
{
if(d>0)
{
d=k%c;
if(d!=0)
printf("%d * %d = %d\n",k,c,d);
k=c;
c=d;
}
}
printf("GCD of a and b is=%d",k);
getch();
return 0;
}
To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.
//using Euclidian algorithm.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c,k,d;
clrscr();
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
c=a%b;
printf("%d * %d = %d\n",a,b,c);
k=b<a?b:a;
while(c>0)
{
if(d>0)
{
d=k%c;
if(d!=0)
printf("%d * %d = %d\n",k,c,d);
k=c;
c=d;
}
}
printf("GCD of a and b is=%d",k);
getch();
return 0;
}
To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.