|
Swap(arr[i], arr[minIndex])
|
Sana | 07.01.2024 | Hajmi | 355,63 Kb. | | #131618 |
Bog'liq Shukurov Sardor amaliy ish 2 Variant – 17
O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
Amaliy ish
Bajardi: Shukurov Sardor
Qabul qildi: ________________
Toshkent 2023
Variant – 17
1 – topshiriq.
Dastur kodi:
#include
#include
using namespace std;
int main()
{
int n;
cout << "Shukurov Sardor " << endl;
cout << "N sonini kiriting := ";
cin >> n;
cout << "Tasodifiy sonlar := ";
for (int i = 1; i <= n; i ++)
{
int a;
cin >> a;
if (a % 2 == 0)
cout << "juft son := " << a << endl;
}
}
2 – topshiriq:
Dastur kodi:
#include
#include
using namespace std;
void selectionSort(vector& arr) {
int n = arr.size();
for (int i = 0; i < n-1; i++) {
int minIndex = i;
for (int j = i+1; j < n; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
swap(arr[i], arr[minIndex]);
}
}
int main() {
int n;
cout << "Massiv uzunligini kiriting: ";
cin >> n;
vector b(n);
for (int i = 0; i < n; i++) {
cout << "Element #" << i+1 << " ni kiriting: ";
cin >> b[i];
}
vector musbatlar;
for (int i = 0; i < n; i++) {
if (b[i] > 0) {
musbatlar.push_back(b[i]);
}
}
selectionSort(musbatlar);
cout << "Manfiy sonlar: ";
for (int i = 0; i < n; i++) {
if (b[i] < 0) {
cout << b[i] << " ";
}
}
cout << endl << "Musbat sonlar: ";
for (int i = 0; i < musbatlar.size(); i++) {
cout << musbatlar[i] << " ";
}
return 0;
}
|
| |