Chiziqli algaritmlarni dasturlash


-misol A va b butun sonlardan qaysi biri juft ekanligini aniqlovchi dastur tuzing


Download 25.95 Kb.
bet3/4
Sana17.10.2023
Hajmi25.95 Kb.
#1705747
1   2   3   4
Bog'liq
pythonda mavzulashtirilgan masala va misollar to\'plami

10-misol A va b butun sonlardan qaysi biri juft ekanligini aniqlovchi dastur tuzing.
Yechish:
print("a sonni kiriting")
a=int(input())
print("b sonni kiriting")
b=int(input())
if a%2==0 and b%2==0:
print(" Ikkiala son ham juft son")
elif a%2==0:
print("A son juft son")
elif b%2==0:
print("B son juft son")
else:
print("Ikkala son ham toq son")
11-misol a va b sondan qaysi biri juft ekanligini aniqlovchi dastur tuzing
Yechish:
x=int(input())
y=int(input())
if x%2==0 and y%2==0:
print( "Ikkala son ham juft son")
elif x%2==0 and y%2!=0:
print(x, " son juft son" )
print(y ,"son toq son")
elif x%2!=0 and y%2==0:
print(x,"son toq son")
print(y ,"son juft son")
else :
print("ikkala son ham toq")

Takrorlanuvchi algaritmlar.For operatori
1-misol. a va b sonlar berilgan. a dan b gacha bо‘lgan barcha sonlarni chiqaruvchi dastur tuzing. Bu yerda a <= b
a=int(input())
b=int(input())
if afor i in range(a,b):
print(i)

2-misol. a va b sonlar berilgan. Agar a < b bо‘lsa, a dan b gacha bо‘lgan sonlarni о‘sish
tartibida, aks holda kamayish tartibida chiqaring
a=int(input())
b=int(input())
if afor i in range(a,b):
print(i)

else:
for i in range(a,b,-1):
print(i)

3-misol. 1 dan 10 gacha bо‘lgan natural sonlar kvadratlarini chiqaruvchi dastur tuzing
for i in range(1,10):
print(i**2)

4-misol. 1 dan 10 gacha bо‘lgan natural sonlar yig‘indisini chiqaruvchi dastur tuzing.
s=0
for i in range(1,10):
s=s+i
print(s)


Download 25.95 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling