Advertisement
lamaulfarid

matdis_5.4_nomor 15

Dec 7th, 2020 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. # Nama : Ahmad Lamaul Farid
  2. # NRP : 05111940000134
  3. # Kelas : Matematika Diskrit A
  4.  
  5. # inisialisasi nilai untuk x dan y dengan bilangan positif integer dengan syarat: x < y
  6. x = 16
  7. y = 20
  8.  
  9. # fungsi untuk menghitung faktor terbesar dari dua buah bilangan positif integer dengan syarat: a < b
  10. def gcd(a, b):
  11.     if a == 0:
  12.         return b
  13.     else:
  14.         if a < b-a:
  15.             return gcd(a, b-a)
  16.         else:
  17.             return gcd(b-a, a)
  18.  
  19.  
  20. # print hasil dari faktor terbesar dua buah bilangan positif integer
  21. print(gcd(x, y))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement