Bajardi: Jumayev u qabul qildi: Nosirov b qarshi-2023


Download 67.06 Kb.
Sana18.06.2023
Hajmi67.06 Kb.
#1579828
Bog'liq
Dasturlash 2 fani Amaliy ish 2




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

  1. import random

  2. # Define the number of elements in the vector

  3. N = 10

  4. # Create a list of N random numbers

  5. vector = [random.randint(1, 100) for i in range(N)]

  6. # Print the original vector

  7. print("Original vector:", vector)

  8. # Sort the vector in descending order

  9. vector.sort(reverse=True)

  10. # Print the sorted vector

  11. print("Sorted vector:", vector)

  1. Arifmetik progressiyaning dastlabki n ta hadidan vector hosil qiling n.

  1. # Define the first term, common difference, and number of terms

  2. a = 2

  3. d = 3

  4. n = 5


  5. # Create an empty list to store the terms

  6. progression = []

  7. # Generate the first n terms of the arithmetic progression

  8. for i in range(n):

  9. term = a + i*d

  10. progression.append(term)

  11. # 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.

  1. Ikkita bir xil elementga ega bo`lgan N o`lchamli butun tipli massiv berilgan. Bir xil elementlar nomeri topilib o`sish tartibida chiqarilsin.

  1. # Define the integer array with duplicate elements

  2. arr = [3, 5, 2, 7, 4, 5, 1, 6, 3]

  3. # Find the duplicate elements

  4. duplicates = []

  5. for i in range(len(arr)):

  6. for j in range(i+1, len(arr)):

  7. if arr[i] == arr[j]: duplicates.append(arr[i])

  8. # Remove the duplicate elements in ascending order

  9. for duplicate in sorted(set(duplicates)):

  10. arr.remove(duplicate)

  11. # Print the resulting array

  12. 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.
Download 67.06 Kb.

Do'stlaringiz bilan baham:




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