Advertisement
edutedu

cmmdc a n numere

Mar 5th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int a[100];
  5. int cmmdc(int st, int dr)
  6. {
  7. int m,c,b,r;
  8. if(st==dr)
  9. return a[st];
  10. else
  11. {
  12. m=(st+dr)/2;
  13. b=cmmdc(st,m);
  14. c=cmmdc(m+1,dr);
  15. r=b%c;
  16. while(r)
  17. {
  18. b=c;
  19. c=r;
  20. r=b%c;
  21. }
  22. return c;
  23. }
  24. }
  25. int main()
  26. {
  27. int n, i;
  28. cin>>n;
  29. for(i=1; i<=n; i++)
  30. cin>>a[i];
  31. cout<<cmmdc(1, n);
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement