Bajardi: Sarvarjon Oripov Qabul qildi: Axmadjonov Islomjon Variant-5 5. A massiv elementlari qiymatlarini togridan togri qoshish usuli bilan saralash algoritmidan foydalanib kamayish tartibida saralab, eng kichik manfiy elementni ekranga chiqaruvchi dsatur tuzing .
Dastur kodi: #include using namespace std;
void swap(int &a, int &b) { int temp = a; a = b; b = temp; }
void selectionSort(int arr[], int n) { 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;
int arr[n]; cout << "Massiv elementlarini kiriting: "; for (int i = 0; i < n; i++) { cin >> arr[i]; }
selectionSort(arr, n);
int smallestNegative = INT_MAX; for (int i = 0; i < n; i++) { if (arr[i] < 0 && arr[i] < smallestNegative) smallestNegative = arr[i]; }
if (smallestNegative == INT_MAX) cout << "Manfiy element topilmadi." << endl; else cout << "Eng kichik manfiy element: " << smallestNegative << endl;