ayuda
soy muy malo en programacion de echo me gustaria que alguien me puediera orientar sobre un trabajo de clase que tenngo que Hacer se trata, del algoritmo de euclides, si alguienn sabe pues... muchas gracias anticipadas
te envio un programa que encuentra el maximo comun divisor por medio del algoritmo de euclides y de paso encuentra tambien el minimo comuin multiplo.
exito
// program k2a15.CPP - page 19
// compute: a - GCD - the greatest common divisor
// b - LCM - the least common multiply
// 19/6/2001
// written in Borland CPP ver 3.1
#include <conio.h>
#include <iostream.h>
int GetNum(char a)
{
for(int x = -1; x < 0;)
{
cout << a << " = ";
cin >> x;
}
return x;
} // GET NUM
int gcd(int a, int b) // maximo comun divisor
{
while(a != b)
{
if(a > b)
a -= b;
else
b -= a;
}
return a;
} // GCD
int lcm(int a, int b)
{
long aa = a;
return aa*b/gcd(a,b);
} // LCM
void main()
{
int a,b;
clrscr();
a = GetNum('a');
b = GetNum('b');
cout << endl << "GCD = " << gcd(a,b) << endl;
cout << "LCM = " << lcm(a,b) << endl;
getch();
} // MAIN
exito
// program k2a15.CPP - page 19
// compute: a - GCD - the greatest common divisor
// b - LCM - the least common multiply
// 19/6/2001
// written in Borland CPP ver 3.1
#include <conio.h>
#include <iostream.h>
int GetNum(char a)
{
for(int x = -1; x < 0;)
{
cout << a << " = ";
cin >> x;
}
return x;
} // GET NUM
int gcd(int a, int b) // maximo comun divisor
{
while(a != b)
{
if(a > b)
a -= b;
else
b -= a;
}
return a;
} // GCD
int lcm(int a, int b)
{
long aa = a;
return aa*b/gcd(a,b);
} // LCM
void main()
{
int a,b;
clrscr();
a = GetNum('a');
b = GetNum('b');
cout << endl << "GCD = " << gcd(a,b) << endl;
cout << "LCM = " << lcm(a,b) << endl;
getch();
} // MAIN