Advertisement
nguyenhappy92

hãy tìm ước chung lớn nhất của hai giá trị a và b

Oct 8th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. //Cho hai số nguyên dương a và b, hãy tìm ước chung lớn nhất của hai giá trị này
  2. // cho 2 so nguyen duong a va b hay tim uoc chung lon nhat 2 so
  3. // Khai bao thu vien
  4. #include<stdio.h>
  5. #include<conio.h>
  6. int UCLN(int a,int b);
  7. void main()
  8. {
  9. int a,b;
  10. scanf("%d%d",&a,&b);
  11. printf("%d",UCLN(a,b));
  12. }
  13. int UCLN(int a,int b)
  14. {
  15. while(a!=b)
  16. {
  17. if(a>b)
  18. {
  19. a=a-b;
  20. }
  21. else
  22. {
  23. b=b-a;
  24. }
  25. }
  26. return a;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement