Sa se calculeze cmmdc pentru n numere utilizand metoda divide et impera
#include<iostream.h>
int cmmdc(int a[20], int li, int ls)
{ if(li==ls) return a[li];
else
{ int x,y;
x=cmmdc(a,li,(li+ls)/2);
y=cmmdc(a,(li+ls)/2+1,ls);
while(x!=y)
if(x>y) x=x-y;
else y=y-x;
return x;
}
}
void main()
{
int a[20],n,i;
cout<<“n=”;cin>>n;
for(i=1;i<=n;i++) cin>>a[i];
cout<<“cmmdc este: “<<cmmdc(a,1,n);
}