cmmdc recursiv

Sa se afle cmmdc pentru 2 numere utilizand varianta recursiva

#include<iostream.h>
int a,b;

int cmmdc(int a,int b)
{
if(a==b) return a;
else
if (a>b) return cmmdc(a-b,b);
else return cmmdc(a,b-a);
}

void main()
{
cout<<“a=”;cin>>a;
cout<<“b=”;cin>>b;
cout<<“cmmdc: “<<cmmdc(a,b);
}

{module orizontal600}

Leave a Comment