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)
Do'stlaringiz bilan baham: |