CEL MAI MARE DIVIZOR COMUN - ALGORITMUL LUI EUCLID (metoda impartirilor succesive)

#include<iostream.h>
void main()
{
int a,b,r;
cout<<"a=";cin>>a;
cout<<"b=";cin>>b;
r=a%b;
while(r)
{
a=b;
b=r;
r=a%b;
}
cout<<"cmmdc: "<<b;
}

CEL MAI MARE DIVIZOR COMUN - ALGORITMUL LUI NICOMAHUS (metoda scaderilor repetate)

#include<iostream.h>
void main()
{
int a,b,r;
cout<<"a=";cin>>a;
cout<<"b=";cin>>b;
while(a!=b)
if(a>b) a=a-b;
else b=b-a;
cout<<"cmmdc: "<<b;
}

{joscommentenable}