1-Lobaratoriya ishi


Download 238.65 Kb.
Sana15.06.2023
Hajmi238.65 Kb.
#1484623
Bog'liq
Jamshid Algoritm


1-Lobaratoriya ishi:
Koeffitsiyentlari a=3, b= 10, c=3 bo’lgan kvadrat tenglama ildizlari topilsin; Tomonlari a=5, b=11, c=9 bo’lgan uchburchak yuzi topilsin

Kvadrat tenglamani ildizlari:


import math


a = int(input('a= '))


b = int(input('b= '))
c = int(input('c= '))

D = b**2 - 4*a*c


if D >= 0:


x1 = (-b + math.sqrt(D)) / (2*a)
x2 = (-b - math.sqrt(D)) / (2*a)
print("Kvadrat tenglama ildizlari:")
print("x1 =", x1)
print("x2 =", x2)
else:
print("Ildizlar mavjud emas")

Natijada quyidagi chiqadi:


Kvadrat tenglama ildizlari:


x1 = -0.3333333333333333
x2 = -3.0



Uchburchak yuzi:

a = int(input('a= '))


b = int(input('b= '))
c = int(input('c= '))

s = (a + b + c) / 2


area = (s * (s-a) * (s-b) * (s-c)) ** 0.5

print("Uchburchak yuzi:", area)


Natijada quyidagi chiqadi:


Uchburchak yuzi: 22.18529918662356





Quyidagi tenglamalarning yechimlarini toping: X3-19x+3=0


Tenglama Kubik tenglama ekanligi sababli, uning yechimi uchun kub ildizni topishimiz kerak. Bu uchun quyidagi formuladan foydalanamiz:
X = (q + ((q 2) + (r - p 2) 3) (1/2)) (1/3) + (q - ((q 2) + (r - p 2) 3) (1/2)) (1/3)
bu yerda:
p = -19 / 3
q = (p3 + ((33)(3))/27)(1/2)
r = ((-19 / 3)2 (1 / 4)) + ((-19 / 3)3 / 27) + (32 (-19 / 3)) / 27

Soddalashtirgandan keyin, bizga manba kod kerak bo'ladi:


import math


p = -19 / 3
q = math.sqrt((p**3 + ((3**2)*(3))/27))
r = (((-19 / 3)**2 * (1 / 4)) + (((-19 / 3)**3) / 27) + ((math.pow(3,2 ) * (-19 / 3))) /27)
X1 = (
q
+(math.pow(
q**2
+(r-p**2)**(1/2),
(1/3)
)
)
+(math.pow(
q**2
-(r-p**2)**(1/2),
(1/3)
)
)
)
print("Yechim:", X1)
Natija: Yechim: 4.676958483973078
2-Lobaratoriya ishi
Elementlari soni n ta, 1 dan boshlab indekslangan bir o’lchamli massiv quyidagi formulabilan aniqlangan:
a= (b∙i2+c∙i+d) mod m;
Bu yerda “mod” amali qoldiq hisoblanadi. Sizning vazifangiz bu massiv elentlarinikamaymaslik tartibda saralab, saralangandan so’ng q ta so’rovga javob berish. Har bir i-so’rovda saralangan massivdagi ki-o’rinda turgan elementning qiymatini chiqarishso’raladi.

# 1. Massivni yaratamiz va qiymatlarni hisoblaymiz:


def create_array(n, b, c, d, m):


arr = []
for i in range(1, n+1):
ai = (b*i**2 + c*i + d) % m
arr.append(ai)
return arr

# 2. Massivni saralab chiqamiz:


def sort_array(arr):


arr.sort()
return arr

# 3. So'rovga javob berish uchun funksiya yaratamiz:


def query(arr, k):


return arr[k-1]

# 4. Barcha funksiyalarni jamiy kodga joylashtiramiz:


n = int(input("Massiv uzunligini kiriting: "))


b = int(input("b ni kiriting: "))
c = int(input("c ni kiriting: "))
d = int(input("d ni kiriting: "))
m = int(input("m ni kiriting: "))

arr = create_array(n, b, c, d, m)


sorted_arr = sort_array(arr)

q = int(input("So'rov sonini kiriting: "))


for i in range(q):


k = int(input(f"{i+1}-so'rov uchun k qiymatini kiriting: "))
print(query(sorted_arr, k))
Natija:
Massiv uzunligini kiriting: 7
b ni kiriting: 8
c ni kiriting: 4
d ni kiriting: 7
m ni kiriting: 31
So'rov sonini kiriting: 7
1-so'rov uchun k qiymatini kiriting: 5
24
2-so'rov uchun k qiymatini kiriting: 7
29
3-so'rov uchun k qiymatini kiriting: 1
9
4-so'rov uchun k qiymatini kiriting: 5
24
5-so'rov uchun k qiymatini kiriting: 3
6-so'rov uchun k qiymatini kiriting: 6
27
7-so'rov uchun k qiymatini kiriting: 3
16





3-Lobaratoriya ishi

n = int(input())


matrix = []
for i in range(n):
row = list(map(int, input().split()))
matrix.append(row)

max_diagonal = -101


min_diagonal = 101
for i in range(n):
if matrix[i][i] > max_diagonal:
max_diagonal = matrix[i][i]
if matrix[i][n-i-1] < min_diagonal:
min_diagonal = matrix[i][n-i-1]

print(max_diagonal, min_diagonal)




Natija:
5
14 0 -46 45 13
81 -25 47 -10 7
84 54 -67 57 55
53 -37 28 -73 41
76 46 -14 31 46
46 -67



Download 238.65 Kb.

Do'stlaringiz bilan baham:




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