Skip to content
Snippets Groups Projects
Commit 836325cb authored by Martin Mareš's avatar Martin Mareš
Browse files

01: Příklady

parent 1458798f
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# Počítání ciferného součtu
n = int(input())
soucet = 0
while n > 0:
cislice = n % 10
soucet += cislice
n = n // 10
print(soucet)
#!/usr/bin/env python3
# Největší společný dělitel: Euklidův algoritmus s modulem
x = int(input())
y = int(input())
while x > 0 and y > 0:
if x > y:
x %= y
else:
y %= x
if x > 0:
print(x)
else:
print(y)
#!/usr/bin/env python3
# Největší společný dělitel: Euklidův algoritmus s odčítáním
x = int(input())
y = int(input())
while x != y:
if x > y:
x -= y
else:
y -= x
print(x)
#!/usr/bin/env python3
# Největší společný dělitel: Euklidův algoritmus s pár triky navíc
x = int(input())
y = int(input())
while y > 0:
x, y = y, x%y
print(x)
#!/usr/bin/env python3
# Otestuje, zda číslo je prvočíslem
n = int(input())
d = 2
mam_delitele = False
while d < n:
if n%d == 0:
print("Číslo", n, "je dělitelné", d)
mam_delitele = True
break
d += 1
if not mam_delitele:
print("Číslo", n, "je prvočíslo")
#!/usr/bin/env python3
# Vypíše všechna prvočísla od 1 do n
n = int(input())
x = 2
while x <= n:
d = 2
mam_delitele = False
while d < x:
if x%d == 0:
mam_delitele = True
break
d += 1
if not mam_delitele:
print(x)
x += 1
#!/usr/bin/env python3
# Skládáme číslo po číslicích
print("Zadávej číslice, ukonči -1:")
n = 0
while True:
cislice = int(input())
if cislice < 0:
break # Vyskočíme z cyklu
n = 10*n + cislice
print(n)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment