Chiziqli algaritmlarni dasturlash


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

5-misol. x ga karrali n ta sonni chiqarish dasturini tuzing.
x=int(input())
n=int(input())
i=0
for i in range(n):
s=i*x
print(s)

6-misol. 1 dan n gacha bо‘lgan natural sonlar kvadratlari yig‘indisini aniqlovchi dastur yozing.
n=int(input())
s=0
for i in range(1,n):
s=s+i**2
print(s)

7-misol. n>=2 shartni qanoatlantiruvchi n soni berilgan. Ushbu ifodani hisoblovchi dastur tuzing. d=1*2+2*3+...+(n–1)*n
n=int(input())
s=0
if n>=2:
for i in range(2,n+1):
s=s+(i-1)*i
print(s)

8-misol. Bir nechta son berilgan. Ular orasida qancha 2 soni bor ekanligini aniqlovchi dastur tuzing.
n=int(input())
s=0
for i in range(n):
i=int(input())
if i==2:
s=s+1
print(s)

9-misol. S=11+13+15+…+49 yig‘indini hisoblash dasturini tuzing.
s=0
for i in range(11,50):
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