O’ZBEKISTON RESPUBLIKASI RAQAMLI TEXNOLOGIYALAR
VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
QARSHI FILIALI
TELEKOMMUNIKATSIYA TEXNOLOGIYALARI VA KASBIY TA’LIM FAKULTETI
KI-11-21 Sirtqi GURUH TALABASINING
DASTURLASH 2
FANIDAN
A M A L I Y I S H
Bajardi: Jumayev U
Qabul qildi: Nosirov B
QARSHI-2023
2 - AMALIY ISH
Mavzu: STL kutubxonalari. Kontеynеr sinflar, kontеynеrlar (kollеksiyalar). Chiziqli konteynerlar. Assosiativ kontеynеrlar. Tartiblanmagan assosiativ kontеynеrlar
Amaliy ishdan maqsad: C++ dasturlash tilida STL kutubxonalari, konteynerlar va konteyner sinflaridan foydalanish ko‘nikmalarini shakllantirish.
Amaliy ish bo’yicha sinov savollari
I. N ta tasodifiy sonlardan iborat vector hosil qiling, elementlarini kamayish tartibida saralang
import random
# Define the number of elements in the vector
N = 10
# Create a list of N random numbers
vector = [random.randint(1, 100) for i in range(N)]
# Print the original vector
print("Original vector:", vector)
# Sort the vector in descending order
vector.sort(reverse=True)
# Print the sorted vector
print("Sorted vector:", vector)
Arifmetik progressiyaning dastlabki n ta hadidan vector hosil qiling n.
# Define the first term, common difference, and number of terms
a = 2
d = 3
n = 5
# Create an empty list to store the terms
progression = []
# Generate the first n terms of the arithmetic progression
for i in range(n):
term = a + i*d
progression.append(term)
# Print the resulting vector
print(progression)
Masalan, a = 2, d = 3 va n = 5 bo'lsa, natijada vektor [2, 5, 8, 11, 14] bo'ladi.
Ikkita bir xil elementga ega bo`lgan N o`lchamli butun tipli massiv berilgan. Bir xil elementlar nomeri topilib o`sish tartibida chiqarilsin.
# Define the integer array with duplicate elements
arr = [3, 5, 2, 7, 4, 5, 1, 6, 3]
# Find the duplicate elements
duplicates = []
for i in range(len(arr)):
for j in range(i+1, len(arr)):
if arr[i] == arr[j]: duplicates.append(arr[i])
# Remove the duplicate elements in ascending order
for duplicate in sorted(set(duplicates)):
arr.remove(duplicate)
# Print the resulting array
print(arr)
Misol uchun, agar arr = [3, 5, 2, 7, 4, 5, 1, 6, 3] bo'lsa, 3 va 5-sonli takroriy elementlarni olib tashlaganingizdan so'ng, olingan massiv [1, 2, 4, 6, 7] bo'ladi. ortib borayotgan tartibda.
Do'stlaringiz bilan baham: |