Guruh Abdurashidov Bexruz


Download 133.09 Kb.
bet1/4
Sana16.06.2023
Hajmi133.09 Kb.
#1517862
  1   2   3   4
Bog'liq
Algaritim loyihalash1 2-variant


O
‘zbekiston Respublikasi Raqamli texnologiyalari vazirligi


Muhammad al-Xorazmiy nomidagi Toshkent axborot texnologiyalari universiteti


Algoritmlarni loyihalash fanidan amaliy ish

Bajardi316_21 guruh
Abdurashidov Bexruz
Tekshirdi: Ravshanov Anvar
Toshkent-2023

1-Amaliy ishi
Mavzu: Massiv elementlarini tartiblashtirish. Matrisa maksimal, minimal elementini aniqlash algoritmi. Matrisalarni ko’paytirish dasturi. Amallar tartibini baholash.

Bajarilish tartibi:

2. Kod Java scriptda da yozildi:
let nums = [3, 5, 7, 9]; // massivni e'lon qilamiz
let firstEven = null; // birinchi juft sonni ajratish uchun o'zgaruvchi
for (let i = 0; i < nums.length; i++) {
if (nums[i] % 2 == 0) { // agar son juft bo'lsa
firstEven = nums[i]; // birinchi juft sonni ajratamiz va tsikldan chiqamiz
break;
}
}

if (firstEven == null) { // agar juft sonlar topilmagan bo'lsa


console.log("Massivda juft sonlar yo'q");
} else {
for (let i = 0; i < nums.length; i++) {
if (nums[i] % 2 == 0) { // agar son juft bo'lsa
nums[i] *= firstEven; // sonni birinchi juft sonning qiymatiga ko'paytiramiz
}
}
console.log(nums); // [3, 5, 7, 9]
}


Blocksxemasi:

+-------------------------+


| nums = [3, 5, 7, 9] |
| firstEven = null |
| i = 0 |
+-------------------------+
|
| nums[i] % 2 != 0
v
+-------------------------+
| "Massivda juft sonlar yo'q"|
+-------------------------+

+----+ nums[i] % 2 == 0 +-------------------------+


| i++|-------------------------------> firstEven = nums[i] |
+----+ | break |
+-------------------------+
|
v
+-------------------------+
| i = 0 |
+-------------------------+
|
+---------------------+ | nums[i] % 2 == 0
| nums[i] *= firstEven|<---+
+---------------------+
|
v
+---------+
| i++ |
+---------+
|
v
+------------------+
| i < nums.length? |
+------------------+
|
v
+-------+
| End |
+-------+



Download 133.09 Kb.

Do'stlaringiz bilan baham:
  1   2   3   4




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