Home » Category » C & C++

C & C++: This program will figure out the greatest common divisor in two numbers you give

200| Mon, 12 May 2008 14:54:00 GMT| faust| Comments (0)
#include
#define d b%a
#define e a%b

void main()
{
int a,b,c,y,z,m,n;
printf("This program will figure out the greatest common divisor in two numbers you give.\n");
printf("Please enter the first number.\n");
scanf("%d",&a);
printf("Please enter the second number.\n");
scanf("%d",&b);
if(b>a)
{
if(d==0)
c=a;

if(d==1)
c=1;

if(d>1)
{
while(d!=0 && d!=1)
{
y=a%(d);
a=b;
d=a;
}
if((d)==0)
a=c;
if((d)==1)
c=1;
}
}

if(a>b)
{
if((e)==0)
b=c;

if((e)==1)
c=1;

if((e)>1)
{
while(a%b!=0 && a%b!=1)
{
z=b%(e);
b=a;
e=b;
}
if((e)==0)
b=c;
if((e)==1)
c=1;
}
}

if(a==b)
c=a;

printf("The GCD is %d",c);
}

Keywords & Tags: program, figure, out, greatest, common, divisor, two, numbers, give, c++

URL: http://programming.itags.org/c-c++/199414/
 
«« Prev - Next »» 0 helpful answers below.

C & C++ Hot Answers

C & C++ New questions

C & C++ Related Categories